diff --git a/purchase_deposit_analytic/README.rst b/purchase_deposit_analytic/README.rst new file mode 100644 index 00000000000..329d063b323 --- /dev/null +++ b/purchase_deposit_analytic/README.rst @@ -0,0 +1,85 @@ +=========================== +Purchase Deposit - Analytic +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:86afc7e366c234f0bc33ed4108f3fad5a660d42c60f3f549ac0ebda2953a4b75 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/18.0/purchase_deposit_analytic + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_deposit_analytic + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allow purchase order to register deposit with analytic +account and analytic tag + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Ecosoft + +Contributors +------------ + +- Saran Lim. + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-Saran440| image:: https://github.com/Saran440.png?size=40px + :target: https://github.com/Saran440 + :alt: Saran440 + +Current `maintainer `__: + +|maintainer-Saran440| + +This module is part of the `OCA/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_deposit_analytic/__init__.py b/purchase_deposit_analytic/__init__.py new file mode 100644 index 00000000000..14cd1b0579c --- /dev/null +++ b/purchase_deposit_analytic/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import wizard diff --git a/purchase_deposit_analytic/__manifest__.py b/purchase_deposit_analytic/__manifest__.py new file mode 100644 index 00000000000..e2029e5460b --- /dev/null +++ b/purchase_deposit_analytic/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Purchase Deposit - Analytic", + "summary": "Add analytic on wizard register deposit", + "version": "18.0.1.0.0", + "category": "Purchase Management", + "license": "AGPL-3", + "author": "Ecosoft, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/purchase-workflow", + "depends": ["purchase_deposit"], + "data": [ + "wizard/purchase_make_invoice_advance_views.xml", + ], + "installable": True, + "maintainers": ["Saran440"], +} diff --git a/purchase_deposit_analytic/i18n/purchase_deposit_analytic.pot b/purchase_deposit_analytic/i18n/purchase_deposit_analytic.pot new file mode 100644 index 00000000000..bd35ccc247f --- /dev/null +++ b/purchase_deposit_analytic/i18n/purchase_deposit_analytic.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_deposit_analytic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: purchase_deposit_analytic +#: model:ir.model.fields,field_description:purchase_deposit_analytic.field_purchase_advance_payment_inv__account_analytic_id +msgid "Analytic Account" +msgstr "" + +#. module: purchase_deposit_analytic +#: model:ir.model.fields,field_description:purchase_deposit_analytic.field_purchase_advance_payment_inv__analytic_tag_ids +msgid "Analytic Tags" +msgstr "" + +#. module: purchase_deposit_analytic +#: model:ir.model,name:purchase_deposit_analytic.model_purchase_advance_payment_inv +msgid "Purchase Advance Payment Invoice" +msgstr "" diff --git a/purchase_deposit_analytic/pyproject.toml b/purchase_deposit_analytic/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_deposit_analytic/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_deposit_analytic/readme/CONTRIBUTORS.md b/purchase_deposit_analytic/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..ceddb727fad --- /dev/null +++ b/purchase_deposit_analytic/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Saran Lim. \ diff --git a/purchase_deposit_analytic/readme/DESCRIPTION.md b/purchase_deposit_analytic/readme/DESCRIPTION.md new file mode 100644 index 00000000000..893a8357947 --- /dev/null +++ b/purchase_deposit_analytic/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allow purchase order to register deposit with analytic +account and analytic tag diff --git a/purchase_deposit_analytic/static/description/icon.png b/purchase_deposit_analytic/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_deposit_analytic/static/description/icon.png differ diff --git a/purchase_deposit_analytic/static/description/index.html b/purchase_deposit_analytic/static/description/index.html new file mode 100644 index 00000000000..d7c2ed982e2 --- /dev/null +++ b/purchase_deposit_analytic/static/description/index.html @@ -0,0 +1,426 @@ + + + + + +Purchase Deposit - Analytic + + + +
+

Purchase Deposit - Analytic

+ + +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

This module allow purchase order to register deposit with analytic +account and analytic tag

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Ecosoft
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

Saran440

+

This module is part of the OCA/purchase-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/purchase_deposit_analytic/tests/__init__.py b/purchase_deposit_analytic/tests/__init__.py new file mode 100644 index 00000000000..66fd4d6e246 --- /dev/null +++ b/purchase_deposit_analytic/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_purchase_deposit_analytic diff --git a/purchase_deposit_analytic/tests/test_purchase_deposit_analytic.py b/purchase_deposit_analytic/tests/test_purchase_deposit_analytic.py new file mode 100644 index 00000000000..32cbcada455 --- /dev/null +++ b/purchase_deposit_analytic/tests/test_purchase_deposit_analytic.py @@ -0,0 +1,48 @@ +# Copyright 2023 Ecosoft Co., Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.addons.purchase_deposit.tests.test_purchase_deposit import TestPurchaseDeposit + + +class TestPurchaseDepositAnalytic(TestPurchaseDeposit): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.plan_a = cls.env["account.analytic.plan"].create({"name": "Plan A"}) + cls.analytic_account = cls.env["account.analytic.account"].create( + {"name": "Test Analytic Account", "plan_id": cls.plan_a.id} + ) + + def test_create_deposit_with_analytic(self): + """Create deposit invoice and ensure analytic_distribution is passed to the + deposit purchase order line.""" + # Set analytic_distribution on the PO line + self.po.order_line.analytic_distribution = {str(self.analytic_account.id): 100} + self.po.button_confirm() + + ctx = { + "active_id": self.po.id, + "active_ids": [self.po.id], + "active_model": "purchase.order", + "create_bills": True, + } + Wizard = self.env["purchase.advance.payment.inv"].with_context(**ctx) + # default_get should pick up the analytic distribution + defaults = Wizard.default_get(["analytic_distribution"]) + self.assertEqual( + defaults.get("analytic_distribution"), + {str(self.analytic_account.id): 100}, + ) + + # Create the deposit + wizard = Wizard.create({"advance_payment_method": "percentage", "amount": 10}) + wizard.deposit_account_id = self.account_deposit + wizard.analytic_distribution = {str(self.analytic_account.id): 100} + wizard.create_invoices() + + # The deposit PO line should have the analytic_distribution + deposit_line = self.po.order_line.filtered("is_deposit") + self.assertEqual( + deposit_line.analytic_distribution, + {str(self.analytic_account.id): 100}, + ) diff --git a/purchase_deposit_analytic/wizard/__init__.py b/purchase_deposit_analytic/wizard/__init__.py new file mode 100644 index 00000000000..0267b3097c4 --- /dev/null +++ b/purchase_deposit_analytic/wizard/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import purchase_make_invoice_advance diff --git a/purchase_deposit_analytic/wizard/purchase_make_invoice_advance.py b/purchase_deposit_analytic/wizard/purchase_make_invoice_advance.py new file mode 100644 index 00000000000..8b6573d287d --- /dev/null +++ b/purchase_deposit_analytic/wizard/purchase_make_invoice_advance.py @@ -0,0 +1,46 @@ +# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class PurchaseAdvancePaymentInv(models.TransientModel): + _inherit = "purchase.advance.payment.inv" + + analytic_distribution = fields.Json() + analytic_precision = fields.Integer( + store=False, + default=lambda self: self.env["decimal.precision"].precision_get( + "Percentage Analytic" + ), + ) + company_id = fields.Many2one( + comodel_name="res.company", + default=lambda self: self.env.company, + ) + + @api.model + def default_get(self, field_list): + res = super().default_get(field_list) + active_ids = self.env.context.get("active_ids", []) + purchases = self.env["purchase.order"].browse(active_ids) + + val_default = {} + if purchases: + val_default["company_id"] = purchases.company_id.id + analytic_account_ids = set() + for analytics in purchases.order_line.mapped("analytic_distribution"): + if analytics: + analytic_account_ids.update(int(aa) for aa in analytics.keys()) + if len(analytic_account_ids) == 1: + val_default["analytic_distribution"] = { + str(list(analytic_account_ids)[0]): 100 + } + res.update(val_default) + return res + + def _prepare_advance_purchase_line(self, order, product, tax_ids, amount): + res = super()._prepare_advance_purchase_line(order, product, tax_ids, amount) + if self.analytic_distribution: + res["analytic_distribution"] = self.analytic_distribution + return res diff --git a/purchase_deposit_analytic/wizard/purchase_make_invoice_advance_views.xml b/purchase_deposit_analytic/wizard/purchase_make_invoice_advance_views.xml new file mode 100644 index 00000000000..bec9d0a2601 --- /dev/null +++ b/purchase_deposit_analytic/wizard/purchase_make_invoice_advance_views.xml @@ -0,0 +1,25 @@ + + + + Invoice Orders + purchase.advance.payment.inv + + + + + + + + + + + + +