diff --git a/account_payment_purchase_stock/README.rst b/account_payment_purchase_stock/README.rst new file mode 100644 index 000000000..b69ad2c42 --- /dev/null +++ b/account_payment_purchase_stock/README.rst @@ -0,0 +1,101 @@ +============================== +Account Payment Purchase Stock +============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fbank--payment-lightgray.png?logo=github + :target: https://github.com/OCA/bank-payment/tree/13.0/account_payment_purchase_stock + :alt: OCA/bank-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/bank-payment-13-0/bank-payment-13-0-account_payment_purchase_stock + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/173/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module combines the *account_payment_purchase* module with *purchase_stock*. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module depends on : + +- purchase_stock +- account_payment_purchase + +This module is part of the OCA/bank-payment suite. + +Usage +===== + +This module doesn't add any feature, but it is used by several other modules. + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* Alexis de Lattre +* Alexandre Fayolle +* Danimar Ribeiro +* Raphaël Valyi +* Abraham Anes +* `Tecnativa `_: + + * Pedro M. Baeza + * Vicent Cubells + +* Nikul Chaudhary +* Miquel Raïch +* Andrea Stirpe + +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. + +This module is part of the `OCA/bank-payment `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_purchase_stock/__init__.py b/account_payment_purchase_stock/__init__.py new file mode 100644 index 000000000..83e553ac4 --- /dev/null +++ b/account_payment_purchase_stock/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/account_payment_purchase_stock/__manifest__.py b/account_payment_purchase_stock/__manifest__.py new file mode 100644 index 000000000..bb38d439d --- /dev/null +++ b/account_payment_purchase_stock/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2016 Akretion (). +# Copyright 2017 Tecnativa - Vicent Cubells +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Account Payment Purchase Stock", + "version": "13.0.1.0.0", + "category": "Banking addons", + "license": "AGPL-3", + "summary": "Integrate Account Payment Purchase with Stock", + "author": "Akretion, Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/bank-payment", + "depends": ["account_payment_purchase", "purchase_stock"], + "installable": True, + "auto_install": True, +} diff --git a/account_payment_purchase_stock/i18n/account_payment_purchase_stock.pot b/account_payment_purchase_stock/i18n/account_payment_purchase_stock.pot new file mode 100644 index 000000000..7c9553583 --- /dev/null +++ b/account_payment_purchase_stock/i18n/account_payment_purchase_stock.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_purchase_stock +# +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_payment_purchase_stock +#: model:ir.model,name:account_payment_purchase_stock.model_stock_rule +msgid "Stock Rule" +msgstr "" diff --git a/account_payment_purchase_stock/models/__init__.py b/account_payment_purchase_stock/models/__init__.py new file mode 100644 index 000000000..7d44ef733 --- /dev/null +++ b/account_payment_purchase_stock/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import stock_rule diff --git a/account_payment_purchase_stock/models/stock_rule.py b/account_payment_purchase_stock/models/stock_rule.py new file mode 100644 index 000000000..17ccc5581 --- /dev/null +++ b/account_payment_purchase_stock/models/stock_rule.py @@ -0,0 +1,22 @@ +# Copyright 2015 Tecnativa - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import models + + +class StockRule(models.Model): + _inherit = "stock.rule" + + def _prepare_purchase_order(self, company_id, origins, values): + """Propagate payment mode on MTO/drop shipping.""" + res = super()._prepare_purchase_order(company_id, origins, values) + values = values[0] + partner = values["supplier"].name + if partner: + res["payment_mode_id"] = partner.with_context( + force_company=self.company_id.id + ).supplier_payment_mode_id.id + res["supplier_partner_bank_id"] = self.env[ + "purchase.order" + ]._get_default_supplier_partner_bank(partner) + return res diff --git a/account_payment_purchase_stock/readme/CONTRIBUTORS.rst b/account_payment_purchase_stock/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..2cecd6336 --- /dev/null +++ b/account_payment_purchase_stock/readme/CONTRIBUTORS.rst @@ -0,0 +1,13 @@ +* Alexis de Lattre +* Alexandre Fayolle +* Danimar Ribeiro +* Raphaël Valyi +* Abraham Anes +* `Tecnativa `_: + + * Pedro M. Baeza + * Vicent Cubells + +* Nikul Chaudhary +* Miquel Raïch +* Andrea Stirpe diff --git a/account_payment_purchase_stock/readme/DESCRIPTION.rst b/account_payment_purchase_stock/readme/DESCRIPTION.rst new file mode 100644 index 000000000..e2f5e2891 --- /dev/null +++ b/account_payment_purchase_stock/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module combines the *account_payment_purchase* module with *purchase_stock*. diff --git a/account_payment_purchase_stock/readme/INSTALL.rst b/account_payment_purchase_stock/readme/INSTALL.rst new file mode 100644 index 000000000..6aac06e8e --- /dev/null +++ b/account_payment_purchase_stock/readme/INSTALL.rst @@ -0,0 +1,6 @@ +This module depends on : + +- purchase_stock +- account_payment_purchase + +This module is part of the OCA/bank-payment suite. diff --git a/account_payment_purchase_stock/readme/USAGE.rst b/account_payment_purchase_stock/readme/USAGE.rst new file mode 100644 index 000000000..de3e7fa6b --- /dev/null +++ b/account_payment_purchase_stock/readme/USAGE.rst @@ -0,0 +1 @@ +This module doesn't add any feature, but it is used by several other modules. diff --git a/account_payment_purchase_stock/static/description/icon.png b/account_payment_purchase_stock/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_payment_purchase_stock/static/description/icon.png differ diff --git a/account_payment_purchase_stock/static/description/index.html b/account_payment_purchase_stock/static/description/index.html new file mode 100644 index 000000000..7a1d0a63c --- /dev/null +++ b/account_payment_purchase_stock/static/description/index.html @@ -0,0 +1,447 @@ + + + + + + +Account Payment Purchase Stock + + + +
+

Account Payment Purchase Stock

+ + +

Beta License: AGPL-3 OCA/bank-payment Translate me on Weblate Try me on Runbot

+

This module combines the account_payment_purchase module with purchase_stock.

+

Table of contents

+ +
+

Installation

+

This module depends on :

+
    +
  • purchase_stock
  • +
  • account_payment_purchase
  • +
+

This module is part of the OCA/bank-payment suite.

+
+
+

Usage

+

This module doesn’t add any feature, but it is used by several other modules.

+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
  • Tecnativa
  • +
+
+
+

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.

+

This module is part of the OCA/bank-payment project on GitHub.

+

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

+
+
+
+ + diff --git a/account_payment_purchase_stock/tests/__init__.py b/account_payment_purchase_stock/tests/__init__.py new file mode 100644 index 000000000..96311fcd9 --- /dev/null +++ b/account_payment_purchase_stock/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import test_account_payment_purchase_stock diff --git a/account_payment_purchase_stock/tests/test_account_payment_purchase_stock.py b/account_payment_purchase_stock/tests/test_account_payment_purchase_stock.py new file mode 100644 index 000000000..a6599ba4a --- /dev/null +++ b/account_payment_purchase_stock/tests/test_account_payment_purchase_stock.py @@ -0,0 +1,119 @@ +# Copyright 2013-2015 Tecnativa - Pedro M. Baeza +# Copyright 2017 Tecnativa - Vicent Cubells +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import fields +from odoo.tests import Form + +from odoo.addons.account_payment_purchase.tests.test_account_payment_purchase import ( + TestAccountPaymentPurchase, +) + + +class TestAccountPaymentPurchaseStock(TestAccountPaymentPurchase): + def test_purchase_stock_order_invoicing(self): + self.purchase.button_confirm() + picking = self.purchase.picking_ids[0] + picking.action_confirm() + picking.move_lines.write({"quantity_done": 1.0}) + picking.button_validate() + + invoice = self.env["account.move"].create( + {"partner_id": self.partner.id, "type": "in_invoice"} + ) + with Form(invoice) as inv: + inv.purchase_id = self.purchase + self.assertEqual( + self.purchase.invoice_ids[0].payment_mode_id, self.payment_mode + ) + + def test_picking_from_purchase_order_invoicing(self): + # Test payment mode + stockable_product = self.env["product.product"].create( + {"name": "Test stockable product", "type": "product"} + ) + self.purchase.order_line[0].product_id = stockable_product + self.purchase.button_confirm() + picking = self.purchase.picking_ids[0] + picking.action_confirm() + picking.move_lines.write({"quantity_done": 1.0}) + picking.button_validate() + + invoice = self.env["account.move"].create( + {"partner_id": self.partner.id, "type": "in_invoice"} + ) + invoice.purchase_id = self.purchase + invoice._onchange_purchase_auto_complete() + self.assertEqual(invoice.payment_mode_id, self.payment_mode) + purchase2 = self.purchase.copy() + payment_mode2 = self.payment_mode.copy() + purchase2.payment_mode_id = payment_mode2 + purchase2.button_confirm() + picking = purchase2.picking_ids[0] + picking.action_confirm() + picking.move_lines.write({"quantity_done": 1.0}) + picking.button_validate() + invoice.purchase_id = purchase2 + result = invoice._onchange_purchase_auto_complete() + self.assertEqual( + result and result.get("warning", {}).get("title", False), "Warning" + ) + + def test_picking_from_purchase_order_invoicing_bank(self): + # Test partner_bank + stockable_product = self.env["product.product"].create( + {"name": "Test stockable product", "type": "product"} + ) + self.purchase.order_line[0].product_id = stockable_product + self.purchase.payment_mode_id = False + self.purchase.supplier_partner_bank_id = self.bank + self.purchase.button_confirm() + picking = self.purchase.picking_ids[0] + picking.action_confirm() + picking.move_lines.write({"quantity_done": 1.0}) + picking.button_validate() + + invoice = self.env["account.move"].create( + {"partner_id": self.partner.id, "type": "in_invoice"} + ) + invoice.purchase_id = self.purchase + invoice._onchange_purchase_auto_complete() + self.assertEqual(invoice.invoice_partner_bank_id, self.bank) + purchase2 = self.purchase.copy() + purchase2.supplier_partner_bank_id = self.bank2 + purchase2.button_confirm() + picking = purchase2.picking_ids[0] + picking.action_confirm() + picking.move_lines.write({"quantity_done": 1.0}) + picking.button_validate() + invoice.purchase_id = purchase2 + result = invoice._onchange_purchase_auto_complete() + self.assertEqual( + result and result.get("warning", {}).get("title", False), "Warning" + ) + + def test_stock_rule_buy_payment_mode(self): + route = self.env.ref("purchase_stock.route_warehouse0_buy") + rule = self.env["stock.rule"].search([("route_id", "=", route.id)], limit=1) + rule._run_buy( + procurements=[ + ( + self.env["procurement.group"].Procurement( + self.mto_product, + 1, + self.mto_product.uom_id, + self.env["stock.location"].search([], limit=1), + "Procurement order test", + "Test", + rule.company_id, + { + "company_id": rule.company_id, + "date_planned": fields.Datetime.now(), + }, + ), + rule, + ) + ] + ) + purchase = self.env["purchase.order"].search([("origin", "=", "Test")]) + self.assertEqual(purchase.payment_mode_id, self.payment_mode)