From b48955c943fee2e20e347b17d2fb5c1e615d8d81 Mon Sep 17 00:00:00 2001 From: mreficent Date: Wed, 29 Jan 2020 14:53:43 +0100 Subject: [PATCH] [MIG] account_payment_purchase: Migration to 13.0 --- account_payment_purchase/README.rst | 15 +-- account_payment_purchase/__manifest__.py | 4 +- .../i18n/account_payment_purchase.pot | 2 +- .../models/account_invoice.py | 21 ++-- .../models/purchase_order.py | 2 +- account_payment_purchase/models/stock_rule.py | 16 +-- .../readme/CONTRIBUTORS.rst | 1 + account_payment_purchase/readme/INSTALL.rst | 2 +- .../static/description/index.html | 9 +- .../tests/test_account_payment_purchase.py | 99 ++++++++++--------- 10 files changed, 87 insertions(+), 84 deletions(-) diff --git a/account_payment_purchase/README.rst b/account_payment_purchase/README.rst index 99b201444..869dfefc6 100644 --- a/account_payment_purchase/README.rst +++ b/account_payment_purchase/README.rst @@ -14,16 +14,16 @@ Account Payment Purchase :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/12.0/account_payment_purchase + :target: https://github.com/OCA/bank-payment/tree/13.0/account_payment_purchase :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-12-0/bank-payment-12-0-account_payment_purchase + :target: https://translation.odoo-community.org/projects/bank-payment-13-0/bank-payment-13-0-account_payment_purchase :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/12.0 + :target: https://runbot.odoo-community.org/runbot/173/13.0 :alt: Try me on Runbot -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| This module adds 2 fields on purchase orders: *Bank Account* and *Payment Mode*. These fields are copied from partner to purchase order and then from @@ -44,7 +44,7 @@ Installation This module depends on : -- purchase +- purchase_stock - account_payment_partner This module is part of the OCA/bank-payment suite. @@ -69,7 +69,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -96,6 +96,7 @@ Contributors * Vicent Cubells * Nikul Chaudhary +* Miquel Raïch Maintainers ~~~~~~~~~~~ @@ -110,6 +111,6 @@ 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. +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/__manifest__.py b/account_payment_purchase/__manifest__.py index 94bb77c2b..ce4a618ba 100644 --- a/account_payment_purchase/__manifest__.py +++ b/account_payment_purchase/__manifest__.py @@ -4,11 +4,11 @@ { "name": "Account Payment Purchase", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "category": "Banking addons", "license": "AGPL-3", "summary": "Adds Bank Account and Payment Mode on Purchase Orders", - "author": "Akretion, " "Tecnativa, " "Odoo Community Association (OCA)", + "author": "Akretion, Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/bank-payment", "depends": ["account_payment_partner", "purchase_stock"], "data": ["views/purchase_order_view.xml"], diff --git a/account_payment_purchase/i18n/account_payment_purchase.pot b/account_payment_purchase/i18n/account_payment_purchase.pot index 040bb631d..a8a57db9a 100644 --- a/account_payment_purchase/i18n/account_payment_purchase.pot +++ b/account_payment_purchase/i18n/account_payment_purchase.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: <>\n" "Language-Team: \n" diff --git a/account_payment_purchase/models/account_invoice.py b/account_payment_purchase/models/account_invoice.py index 3502317d8..9b4b4a4c4 100644 --- a/account_payment_purchase/models/account_invoice.py +++ b/account_payment_purchase/models/account_invoice.py @@ -5,27 +5,26 @@ from odoo import _, api, models -class AccountInvoice(models.Model): - _inherit = "account.invoice" +class AccountMove(models.Model): + _inherit = "account.move" - @api.onchange("purchase_id") - def purchase_order_change(self): + @api.onchange("purchase_vendor_bill_id", "purchase_id") + def _onchange_purchase_auto_complete(self): new_mode = self.purchase_id.payment_mode_id.id or False new_bank = self.purchase_id.supplier_partner_bank_id.id or False - res = super(AccountInvoice, self).purchase_order_change() + res = super()._onchange_purchase_auto_complete() or {} if self.payment_mode_id and self.payment_mode_id.id != new_mode: res["warning"] = { "title": _("Warning"), - "message": _("Selected purchase order have different " "payment mode."), + "message": _("Selected purchase order have different payment mode."), } return res self.payment_mode_id = new_mode - if self.partner_bank_id and self.partner_bank_id.id != new_bank: + if self.invoice_partner_bank_id and self.invoice_partner_bank_id.id != new_bank: res["warning"] = { "title": _("Warning"), - "message": _( - "Selected purchase order have different " "supplier bank." - ), + "message": _("Selected purchase order have different supplier bank."), } return res - self.partner_bank_id = new_bank + self.invoice_partner_bank_id = new_bank + return res diff --git a/account_payment_purchase/models/purchase_order.py b/account_payment_purchase/models/purchase_order.py index 5101ab1ef..dba0243e8 100644 --- a/account_payment_purchase/models/purchase_order.py +++ b/account_payment_purchase/models/purchase_order.py @@ -27,7 +27,7 @@ class PurchaseOrder(models.Model): """This function is designed to be inherited""" return partner.bank_ids and partner.bank_ids[0].id or False - @api.onchange("partner_id") + @api.onchange("partner_id", "company_id") def onchange_partner_id(self): super(PurchaseOrder, self).onchange_partner_id() if self.partner_id: diff --git a/account_payment_purchase/models/stock_rule.py b/account_payment_purchase/models/stock_rule.py index eba89d763..51ef93038 100644 --- a/account_payment_purchase/models/stock_rule.py +++ b/account_payment_purchase/models/stock_rule.py @@ -7,18 +7,18 @@ from odoo import models class StockRule(models.Model): _inherit = "stock.rule" - def _prepare_purchase_order( - self, product_id, product_qty, product_uom, origin, values, partner - ): + def _prepare_purchase_order(self, company_id, origins, values): """Propagate payment mode on MTO/drop shipping.""" - values = super(StockRule, self)._prepare_purchase_order( - product_id, product_qty, product_uom, origin, values, partner + res = super(StockRule, self)._prepare_purchase_order( + company_id, origins, values ) + values = values[0] + partner = values["supplier"].name if partner: - values["payment_mode_id"] = partner.with_context( + res["payment_mode_id"] = partner.with_context( force_company=self.company_id.id ).supplier_payment_mode_id.id - values["supplier_partner_bank_id"] = self.env[ + res["supplier_partner_bank_id"] = self.env[ "purchase.order" ]._get_default_supplier_partner_bank(partner) - return values + return res diff --git a/account_payment_purchase/readme/CONTRIBUTORS.rst b/account_payment_purchase/readme/CONTRIBUTORS.rst index 5121c0e9a..3a09c62d4 100644 --- a/account_payment_purchase/readme/CONTRIBUTORS.rst +++ b/account_payment_purchase/readme/CONTRIBUTORS.rst @@ -9,3 +9,4 @@ * Vicent Cubells * Nikul Chaudhary +* Miquel Raïch diff --git a/account_payment_purchase/readme/INSTALL.rst b/account_payment_purchase/readme/INSTALL.rst index 09b853841..c1b712414 100644 --- a/account_payment_purchase/readme/INSTALL.rst +++ b/account_payment_purchase/readme/INSTALL.rst @@ -1,6 +1,6 @@ This module depends on : -- purchase +- purchase_stock - account_payment_partner This module is part of the OCA/bank-payment suite. diff --git a/account_payment_purchase/static/description/index.html b/account_payment_purchase/static/description/index.html index 4d30dae9a..10310f191 100644 --- a/account_payment_purchase/static/description/index.html +++ b/account_payment_purchase/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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

This module adds 2 fields on purchase orders: Bank Account and Payment Mode. These fields are copied from partner to purchase order and then from purchase order to supplier invoice.

@@ -393,7 +393,7 @@ modules in the banking addons conflict with account_payment_extension).

Installation

This module depends on :

    -
  • purchase
  • +
  • purchase_stock
  • account_payment_partner

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

@@ -414,7 +414,7 @@ Invoices without any payment mode are displayed too.

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.

+feedback.

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

@@ -440,6 +440,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Nikul Chaudhary <nikulchaudhary2112@gmail.com>
  • +
  • Miquel Raïch <miquel.raich@forgeflow.com>
  • @@ -449,7 +450,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

    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.

    +

    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/tests/test_account_payment_purchase.py b/account_payment_purchase/tests/test_account_payment_purchase.py index 4738eb216..f882e5111 100644 --- a/account_payment_purchase/tests/test_account_payment_purchase.py +++ b/account_payment_purchase/tests/test_account_payment_purchase.py @@ -3,10 +3,10 @@ # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html from odoo import fields -from odoo.tests import common +from odoo.tests import Form, SavepointCase -class TestAccountPaymentPurchase(common.SavepointCase): +class TestAccountPaymentPurchase(SavepointCase): @classmethod def setUpClass(cls): super(TestAccountPaymentPurchase, cls).setUpClass() @@ -63,7 +63,7 @@ class TestAccountPaymentPurchase(common.SavepointCase): "product_qty": 1.0, "product_id": cls.mto_product.id, "product_uom": cls.uom_id, - "date_planned": fields.Date.today(), + "date_planned": fields.Datetime.today(), "price_unit": 1.0, }, ) @@ -82,14 +82,11 @@ class TestAccountPaymentPurchase(common.SavepointCase): picking.move_lines.write({"quantity_done": 1.0}) picking.button_validate() - invoice = self.env["account.invoice"].create( - { - "partner_id": self.partner.id, - "purchase_id": self.purchase.id, - "account_id": self.partner.property_account_payable_id.id, - } + invoice = self.env["account.move"].create( + {"partner_id": self.partner.id, "type": "in_invoice"} ) - invoice.purchase_order_change() + with Form(invoice) as inv: + inv.purchase_id = self.purchase self.assertEqual( self.purchase.invoice_ids[0].payment_mode_id, self.payment_mode ) @@ -99,84 +96,88 @@ class TestAccountPaymentPurchase(common.SavepointCase): stockable_product = self.env["product.product"].create( {"name": "Test stockable product", "type": "product"} ) - self.purchase.order_line[0].product_id = stockable_product.id + 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.invoice"].create( - { - "partner_id": self.partner.id, - "purchase_id": self.purchase.id, - "account_id": self.partner.property_account_payable_id.id, - } + invoice = self.env["account.move"].create( + {"partner_id": self.partner.id, "type": "in_invoice"} ) - invoice.purchase_order_change() + 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.id + 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.id - result = invoice.purchase_order_change() - self.assertEqual(result["warning"]["title"], "Warning") + 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 patner_bank + # 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.id + self.purchase.order_line[0].product_id = stockable_product self.purchase.payment_mode_id = False - self.purchase.supplier_partner_bank_id = self.bank.id + 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.invoice"].create( - { - "partner_id": self.partner.id, - "purchase_id": self.purchase.id, - "account_id": self.partner.property_account_payable_id.id, - } + invoice = self.env["account.move"].create( + {"partner_id": self.partner.id, "type": "in_invoice"} ) - # Avoid bank company from default_get method - invoice.partner_bank_id = False - invoice.purchase_order_change() - self.assertEqual(invoice.partner_bank_id, self.bank) + 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.id + 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.id - result = invoice.purchase_order_change() - self.assertEqual(result["warning"]["title"], "Warning") + invoice.purchase_id = purchase2 + result = invoice._onchange_purchase_auto_complete() + self.assertEqual( + result and result.get("warning", {}).get("title", False), "Warning" + ) def test_procurement_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( - product_id=self.mto_product, - product_qty=1, - product_uom=self.mto_product.uom_id, - location_id=self.env["stock.location"].search([], limit=1), - name="Procurement order test", - origin="Test", - values={ - "company_id": self.env.user.company_id, - "date_planned": fields.Datetime.now(), - }, + 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)