diff --git a/account_fiscal_position_allowed_journal_purchase/README.rst b/account_fiscal_position_allowed_journal_purchase/README.rst new file mode 100644 index 00000000000..d4ffe34d335 --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/README.rst @@ -0,0 +1,94 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +================================================ +Account Fiscal Position Allowed Journal Purchase +================================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e4c4d830653b1121f77385210bc86cd796c628ae597ebe5418c3f6570d7dafb3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/account_fiscal_position_allowed_journal_purchase + :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-19-0/purchase-workflow-19-0-account_fiscal_position_allowed_journal_purchase + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +When creating an invoice from a purchase order, take the allowed +purchase journal on the fiscal position, if there is exactly one on it. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +See configuration of Account Fiscal Position Allowed Journal. + +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 +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Thomas Binsfeld (https://www.acsone.eu/) + +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-ThomasBinsfeld| image:: https://github.com/ThomasBinsfeld.png?size=40px + :target: https://github.com/ThomasBinsfeld + :alt: ThomasBinsfeld + +Current `maintainer `__: + +|maintainer-ThomasBinsfeld| + +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/account_fiscal_position_allowed_journal_purchase/__init__.py b/account_fiscal_position_allowed_journal_purchase/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_fiscal_position_allowed_journal_purchase/__manifest__.py b/account_fiscal_position_allowed_journal_purchase/__manifest__.py new file mode 100644 index 00000000000..710c113f279 --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Account Fiscal Position Allowed Journal Purchase", + "summary": """ + Use an allowed journal when creating an invoice from a purchase order.""", + "version": "19.0.1.0.0", + "development_status": "Beta", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "maintainers": ["ThomasBinsfeld"], + "website": "https://github.com/OCA/purchase-workflow", + "depends": ["purchase", "account_fiscal_position_allowed_journal"], + "data": [], + "demo": [], +} diff --git a/account_fiscal_position_allowed_journal_purchase/i18n/account_fiscal_position_allowed_journal_purchase.pot b/account_fiscal_position_allowed_journal_purchase/i18n/account_fiscal_position_allowed_journal_purchase.pot new file mode 100644 index 00000000000..1aac7d2ffa1 --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/i18n/account_fiscal_position_allowed_journal_purchase.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_fiscal_position_allowed_journal_purchase +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.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: account_fiscal_position_allowed_journal_purchase +#: model:ir.model,name:account_fiscal_position_allowed_journal_purchase.model_account_move +msgid "Journal Entries" +msgstr "" diff --git a/account_fiscal_position_allowed_journal_purchase/models/__init__.py b/account_fiscal_position_allowed_journal_purchase/models/__init__.py new file mode 100644 index 00000000000..9c0a4213854 --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/models/__init__.py @@ -0,0 +1 @@ +from . import account_move diff --git a/account_fiscal_position_allowed_journal_purchase/models/account_move.py b/account_fiscal_position_allowed_journal_purchase/models/account_move.py new file mode 100644 index 00000000000..81d9a79215c --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/models/account_move.py @@ -0,0 +1,24 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + @api.onchange("purchase_vendor_bill_id", "purchase_id") + def _onchange_purchase_auto_complete(self): + """ + If there is a purchase order and a fiscal position on it which have exactly + one purchase journal allowed, set this journal on the invoice. + """ + # We need to save de PO because the origin method unset it + purchase_order = self.purchase_id + res = super()._onchange_purchase_auto_complete() + fiscal_position = purchase_order.fiscal_position_id + if fiscal_position: + purchase_journal = fiscal_position._get_allowed_journal("purchase") + if purchase_journal: + self.journal_id = purchase_journal + return res diff --git a/account_fiscal_position_allowed_journal_purchase/pyproject.toml b/account_fiscal_position_allowed_journal_purchase/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_fiscal_position_allowed_journal_purchase/readme/CONFIGURE.md b/account_fiscal_position_allowed_journal_purchase/readme/CONFIGURE.md new file mode 100644 index 00000000000..d7ac2827367 --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/readme/CONFIGURE.md @@ -0,0 +1 @@ +See configuration of Account Fiscal Position Allowed Journal. diff --git a/account_fiscal_position_allowed_journal_purchase/readme/CONTRIBUTORS.md b/account_fiscal_position_allowed_journal_purchase/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..4dafe8e6846 --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Thomas Binsfeld \ + () diff --git a/account_fiscal_position_allowed_journal_purchase/readme/DESCRIPTION.md b/account_fiscal_position_allowed_journal_purchase/readme/DESCRIPTION.md new file mode 100644 index 00000000000..01509077c7a --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +When creating an invoice from a purchase order, take the allowed +purchase journal on the fiscal position, if there is exactly one on it. diff --git a/account_fiscal_position_allowed_journal_purchase/static/description/icon.png b/account_fiscal_position_allowed_journal_purchase/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/account_fiscal_position_allowed_journal_purchase/static/description/icon.png differ diff --git a/account_fiscal_position_allowed_journal_purchase/static/description/index.html b/account_fiscal_position_allowed_journal_purchase/static/description/index.html new file mode 100644 index 00000000000..ea5dfffeaa5 --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Account Fiscal Position Allowed Journal Purchase

+ +

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

+

When creating an invoice from a purchase order, take the allowed +purchase journal on the fiscal position, if there is exactly one on it.

+

Table of contents

+ +
+

Configuration

+

See configuration of Account Fiscal Position Allowed Journal.

+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+ +
+

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:

+

ThomasBinsfeld

+

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/account_fiscal_position_allowed_journal_purchase/tests/__init__.py b/account_fiscal_position_allowed_journal_purchase/tests/__init__.py new file mode 100644 index 00000000000..ff78130d0f4 --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_fiscal_position_allowed_journal_purchase diff --git a/account_fiscal_position_allowed_journal_purchase/tests/test_account_fiscal_position_allowed_journal_purchase.py b/account_fiscal_position_allowed_journal_purchase/tests/test_account_fiscal_position_allowed_journal_purchase.py new file mode 100644 index 00000000000..186bb34e8ef --- /dev/null +++ b/account_fiscal_position_allowed_journal_purchase/tests/test_account_fiscal_position_allowed_journal_purchase.py @@ -0,0 +1,109 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields +from odoo.tests.common import TransactionCase + + +class TestAccountFiscalPositionAllowedJournalPurchase(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + # MODELS + cls.account_model = cls.env["account.account"] + cls.account_move_model = cls.env["account.move"] + cls.fiscal_position_model = cls.env["account.fiscal.position"] + cls.journal_model = cls.env["account.journal"] + cls.partner_model = cls.env["res.partner"] + cls.product_product_model = cls.env["product.product"] + cls.purchase_order_model = cls.env["purchase.order"] + + # INSTANCES + cls.fiscal_position_01 = cls.fiscal_position_model.create( + {"name": "Fiscal position 01"} + ) + cls.journal_01 = cls.journal_model.search([("type", "=", "purchase")], limit=1) + cls.journal_02 = cls.journal_01.copy() + cls.partner_01 = cls.partner_model.search([], limit=1) + cls.product_01 = cls.product_product_model.create( + {"name": "Service product 01", "type": "service"} + ) + cls.purchase_order_01 = cls.purchase_order_model.create( + { + "partner_id": cls.partner_01.id, + "fiscal_position_id": cls.fiscal_position_01.id, + "order_line": [ + ( + 0, + 0, + { + "name": "Purchase order line 01", + "product_id": cls.product_01.id, + "product_uom_id": cls.product_01.uom_id.id, + "product_qty": 1, + "price_unit": 1, + "date_planned": fields.Date.today(), + }, + ) + ], + } + ) + cls.purchase_order_01.button_confirm() + cls.invoice_01 = cls.account_move_model.create( + { + "move_type": "in_invoice", + "partner_id": cls.partner_01.id, + "journal_id": cls.journal_01.id, + "fiscal_position_id": cls.fiscal_position_01.id, + } + ) + + def test_01(self): + """ + Data: + - A draft invoice + - A confirmed purchase order with a fiscal position + - Exactly one purchase journal allowed on the fiscal position + Test case: + - Set the purchase order on the invoice + Expected result: + - The allowed purchase journal is set on the invoice + """ + self.fiscal_position_01.allowed_journal_ids = [(6, 0, self.journal_02.ids)] + self.invoice_01.purchase_id = self.purchase_order_01 + self.invoice_01._onchange_purchase_auto_complete() + self.assertEqual(self.invoice_01.journal_id, self.journal_02) + + def test_02(self): + """ + Data: + - A draft invoice + - A confirmed purchase order with no fiscal position + Test case: + - Set the purchase order on the invoice + Expected result: + - The journal of the invoice didn't change + """ + self.purchase_order_01.fiscal_position_id = False + self.invoice_01.purchase_id = self.purchase_order_01 + self.invoice_01._onchange_purchase_auto_complete() + self.assertEqual(self.invoice_01.journal_id, self.journal_01) + + def test_03(self): + """ + Data: + - A draft invoice + - A confirmed purchase order with a fiscal position + - Two purchase journals allowed on the fiscal position + Test case: + - Set the purchase order on the invoice + Expected result: + - The journal of the invoice didn't change + """ + self.fiscal_position_01.allowed_journal_ids = [ + (6, 0, (self.journal_01 | self.journal_02).ids) + ] + self.invoice_01.purchase_id = self.purchase_order_01 + self.invoice_01._onchange_purchase_auto_complete() + self.assertEqual(self.invoice_01.journal_id, self.journal_01)