diff --git a/account_payment_purchase/__manifest__.py b/account_payment_purchase/__manifest__.py index 83e6bd9a5..94bb77c2b 100644 --- a/account_payment_purchase/__manifest__.py +++ b/account_payment_purchase/__manifest__.py @@ -3,22 +3,15 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Account Payment Purchase', - 'version': '12.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)", - 'website': 'https://github.com/OCA/bank-payment', - 'depends': [ - 'account_payment_partner', - 'purchase_stock', - ], - 'data': [ - 'views/purchase_order_view.xml', - ], - 'installable': True, - 'auto_install': True, + "name": "Account Payment Purchase", + "version": "12.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)", + "website": "https://github.com/OCA/bank-payment", + "depends": ["account_payment_partner", "purchase_stock"], + "data": ["views/purchase_order_view.xml"], + "installable": True, + "auto_install": True, } diff --git a/account_payment_purchase/models/__init__.py b/account_payment_purchase/models/__init__.py index 5488e5828..4a3b74aaf 100644 --- a/account_payment_purchase/models/__init__.py +++ b/account_payment_purchase/models/__init__.py @@ -1,5 +1,3 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import account_invoice -from . import purchase_order -from . import stock_rule +from . import account_invoice, purchase_order, stock_rule diff --git a/account_payment_purchase/models/account_invoice.py b/account_payment_purchase/models/account_invoice.py index 03a793159..3502317d8 100644 --- a/account_payment_purchase/models/account_invoice.py +++ b/account_payment_purchase/models/account_invoice.py @@ -8,24 +8,24 @@ from odoo import _, api, models class AccountInvoice(models.Model): _inherit = "account.invoice" - @api.onchange('purchase_id') + @api.onchange("purchase_id") def purchase_order_change(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() 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.'), + res["warning"] = { + "title": _("Warning"), + "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: - res['warning'] = { - 'title': _('Warning'), - 'message': _('Selected purchase order have different ' - 'supplier bank.'), + res["warning"] = { + "title": _("Warning"), + "message": _( + "Selected purchase order have different " "supplier bank." + ), } return res self.partner_bank_id = new_bank diff --git a/account_payment_purchase/models/purchase_order.py b/account_payment_purchase/models/purchase_order.py index b61e2ac85..5101ab1ef 100644 --- a/account_payment_purchase/models/purchase_order.py +++ b/account_payment_purchase/models/purchase_order.py @@ -9,16 +9,16 @@ class PurchaseOrder(models.Model): _inherit = "purchase.order" supplier_partner_bank_id = fields.Many2one( - comodel_name='res.partner.bank', - string='Supplier Bank Account', + comodel_name="res.partner.bank", + string="Supplier Bank Account", domain="[('partner_id', '=', partner_id)]", help="Select the bank account of your supplier on which your company " - "should send the payment. This field is copied from the partner " - "and will be copied to the supplier invoice.", + "should send the payment. This field is copied from the partner " + "and will be copied to the supplier invoice.", ) payment_mode_id = fields.Many2one( - comodel_name='account.payment.mode', - string='Payment Mode', + comodel_name="account.payment.mode", + string="Payment Mode", domain="[('payment_type', '=', 'outbound')]", ) @@ -27,12 +27,13 @@ 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") def onchange_partner_id(self): super(PurchaseOrder, self).onchange_partner_id() if self.partner_id: - self.supplier_partner_bank_id = \ - self._get_default_supplier_partner_bank(self.partner_id) + self.supplier_partner_bank_id = self._get_default_supplier_partner_bank( + self.partner_id + ) self.payment_mode_id = self.partner_id.supplier_payment_mode_id else: self.supplier_partner_bank_id = False diff --git a/account_payment_purchase/models/stock_rule.py b/account_payment_purchase/models/stock_rule.py index 07701cd09..eba89d763 100644 --- a/account_payment_purchase/models/stock_rule.py +++ b/account_payment_purchase/models/stock_rule.py @@ -7,15 +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, product_id, product_qty, product_uom, origin, values, partner + ): """Propagate payment mode on MTO/drop shipping.""" values = super(StockRule, self)._prepare_purchase_order( - product_id, product_qty, product_uom, origin, values, partner) + product_id, product_qty, product_uom, origin, values, partner + ) if partner: - values['payment_mode_id'] = partner.with_context( - force_company=self.company_id.id).supplier_payment_mode_id.id - values['supplier_partner_bank_id'] = ( - self.env['purchase.order']._get_default_supplier_partner_bank( - partner)) + values["payment_mode_id"] = partner.with_context( + force_company=self.company_id.id + ).supplier_payment_mode_id.id + values["supplier_partner_bank_id"] = self.env[ + "purchase.order" + ]._get_default_supplier_partner_bank(partner) return values diff --git a/account_payment_purchase/tests/test_account_payment_purchase.py b/account_payment_purchase/tests/test_account_payment_purchase.py index 8939c48aa..4738eb216 100644 --- a/account_payment_purchase/tests/test_account_payment_purchase.py +++ b/account_payment_purchase/tests/test_account_payment_purchase.py @@ -10,45 +10,66 @@ class TestAccountPaymentPurchase(common.SavepointCase): @classmethod def setUpClass(cls): super(TestAccountPaymentPurchase, cls).setUpClass() - cls.journal = cls.env['account.journal'].create( - {'name': 'Test journal', - 'code': 'TEST', - 'type': 'general'}) - cls.payment_mode = cls.env['account.payment.mode'].create( - {'name': 'Test payment mode', - 'fixed_journal_id': cls.journal.id, - 'bank_account_link': 'variable', - 'payment_method_id': cls.env.ref( - 'account.account_payment_method_manual_in').id}) - cls.partner = cls.env['res.partner'].create( - {'name': 'Test partner', - 'supplier_payment_mode_id': cls.payment_mode.id}) - cls.bank = cls.env['res.partner.bank'].create( - {'bank_name': 'Test bank', - 'acc_number': '1234567890', - 'partner_id': cls.partner.id, - }) - cls.bank2 = cls.env['res.partner.bank'].create( - {'bank_name': 'Test bank #2', - 'acc_number': '0123456789', - 'partner_id': cls.partner.id, - }) - cls.uom_id = cls.env.ref('uom.product_uom_unit').id - cls.mto_product = cls.env['product.product'].create( - {'name': 'Test buy product', - 'type': 'product', - 'uom_id': cls.uom_id, - 'uom_po_id': cls.uom_id, - 'seller_ids': [(0, 0, {'name': cls.partner.id})]}) - cls.purchase = cls.env['purchase.order'].create( - {'partner_id': cls.partner.id, - 'payment_mode_id': cls.payment_mode.id, - 'order_line': [(0, 0, {'name': 'Test line', - 'product_qty': 1.0, - 'product_id': cls.mto_product.id, - 'product_uom': cls.uom_id, - 'date_planned': fields.Date.today(), - 'price_unit': 1.0})]}) + cls.journal = cls.env["account.journal"].create( + {"name": "Test journal", "code": "TEST", "type": "general"} + ) + cls.payment_mode = cls.env["account.payment.mode"].create( + { + "name": "Test payment mode", + "fixed_journal_id": cls.journal.id, + "bank_account_link": "variable", + "payment_method_id": cls.env.ref( + "account.account_payment_method_manual_in" + ).id, + } + ) + cls.partner = cls.env["res.partner"].create( + {"name": "Test partner", "supplier_payment_mode_id": cls.payment_mode.id} + ) + cls.bank = cls.env["res.partner.bank"].create( + { + "bank_name": "Test bank", + "acc_number": "1234567890", + "partner_id": cls.partner.id, + } + ) + cls.bank2 = cls.env["res.partner.bank"].create( + { + "bank_name": "Test bank #2", + "acc_number": "0123456789", + "partner_id": cls.partner.id, + } + ) + cls.uom_id = cls.env.ref("uom.product_uom_unit").id + cls.mto_product = cls.env["product.product"].create( + { + "name": "Test buy product", + "type": "product", + "uom_id": cls.uom_id, + "uom_po_id": cls.uom_id, + "seller_ids": [(0, 0, {"name": cls.partner.id})], + } + ) + cls.purchase = cls.env["purchase.order"].create( + { + "partner_id": cls.partner.id, + "payment_mode_id": cls.payment_mode.id, + "order_line": [ + ( + 0, + 0, + { + "name": "Test line", + "product_qty": 1.0, + "product_id": cls.mto_product.id, + "product_uom": cls.uom_id, + "date_planned": fields.Date.today(), + "price_unit": 1.0, + }, + ) + ], + } + ) def test_onchange_partner_id_purchase_order(self): self.purchase.onchange_partner_id() @@ -58,35 +79,40 @@ class TestAccountPaymentPurchase(common.SavepointCase): self.purchase.button_confirm() picking = self.purchase.picking_ids[0] picking.action_confirm() - picking.move_lines.write({'quantity_done': 1.0}) + 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.invoice"].create( + { + "partner_id": self.partner.id, + "purchase_id": self.purchase.id, + "account_id": self.partner.property_account_payable_id.id, + } + ) invoice.purchase_order_change() self.assertEqual( - self.purchase.invoice_ids[0].payment_mode_id, self.payment_mode) + 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'}) + 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.button_confirm() picking = self.purchase.picking_ids[0] picking.action_confirm() - picking.move_lines.write({'quantity_done': 1.0}) + 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.invoice"].create( + { + "partner_id": self.partner.id, + "purchase_id": self.purchase.id, + "account_id": self.partner.property_account_payable_id.id, + } + ) invoice.purchase_order_change() self.assertEqual(invoice.payment_mode_id, self.payment_mode) purchase2 = self.purchase.copy() @@ -95,31 +121,33 @@ class TestAccountPaymentPurchase(common.SavepointCase): purchase2.button_confirm() picking = purchase2.picking_ids[0] picking.action_confirm() - picking.move_lines.write({'quantity_done': 1.0}) + 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') + self.assertEqual(result["warning"]["title"], "Warning") def test_picking_from_purchase_order_invoicing_bank(self): # Test patner_bank - stockable_product = self.env['product.product'].create( - {'name': 'Test stockable product', - 'type': 'product'}) + 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.payment_mode_id = False self.purchase.supplier_partner_bank_id = self.bank.id self.purchase.button_confirm() picking = self.purchase.picking_ids[0] picking.action_confirm() - picking.move_lines.write({'quantity_done': 1.0}) + 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.invoice"].create( + { + "partner_id": self.partner.id, + "purchase_id": self.purchase.id, + "account_id": self.partner.property_account_payable_id.id, + } + ) # Avoid bank company from default_get method invoice.partner_bank_id = False invoice.purchase_order_change() @@ -129,27 +157,26 @@ class TestAccountPaymentPurchase(common.SavepointCase): purchase2.button_confirm() picking = purchase2.picking_ids[0] picking.action_confirm() - picking.move_lines.write({'quantity_done': 1.0}) + 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') + self.assertEqual(result["warning"]["title"], "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) + 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', + 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(), + "company_id": self.env.user.company_id, + "date_planned": fields.Datetime.now(), }, ) - purchase = self.env['purchase.order'].search([('origin', '=', 'Test')]) + purchase = self.env["purchase.order"].search([("origin", "=", "Test")]) self.assertEqual(purchase.payment_mode_id, self.payment_mode) diff --git a/account_payment_purchase/views/purchase_order_view.xml b/account_payment_purchase/views/purchase_order_view.xml index 8f8713acc..c2fa9cb1f 100644 --- a/account_payment_purchase/views/purchase_order_view.xml +++ b/account_payment_purchase/views/purchase_order_view.xml @@ -1,21 +1,21 @@ - + - account_payment_purchase.purchase_order.form purchase.order - + - - + widget="selection" + /> + -