From 893283a9c273ff2239090b4a9afb7cf19e6ea501 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 25 Nov 2015 22:22:50 +0100 Subject: [PATCH] [FIX] account_payment_purchase: Propagate payment_mode on MTO/drop shipping --- account_payment_purchase/models/__init__.py | 1 + .../models/procurement_order.py | 22 +++++ account_payment_purchase/tests/__init__.py | 5 ++ .../tests/test_account_payment_purchase.py | 84 +++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 account_payment_purchase/models/procurement_order.py create mode 100644 account_payment_purchase/tests/__init__.py create mode 100644 account_payment_purchase/tests/test_account_payment_purchase.py diff --git a/account_payment_purchase/models/__init__.py b/account_payment_purchase/models/__init__.py index 3d13bc0e4..0175eecff 100644 --- a/account_payment_purchase/models/__init__.py +++ b/account_payment_purchase/models/__init__.py @@ -20,5 +20,6 @@ # ############################################################################## +from . import procurement_order from . import purchase_order from . import stock_picking diff --git a/account_payment_purchase/models/procurement_order.py b/account_payment_purchase/models/procurement_order.py new file mode 100644 index 000000000..236ec611a --- /dev/null +++ b/account_payment_purchase/models/procurement_order.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import api, models + + +class ProcurementOrder(models.Model): + _inherit = "procurement.order" + + @api.model + def create_procurement_purchase_order(self, procurement, po_vals, + line_vals): + """Propagate payment mode on MTO/drop shipping.""" + if po_vals.get('partner_id'): + partner = self.env['res.partner'].browse(po_vals['partner_id']) + po_vals['payment_mode_id'] = partner.supplier_payment_mode.id + po_vals['supplier_partner_bank_id'] = ( + self.env['purchase.order']._get_default_supplier_partner_bank( + partner)) + return super(ProcurementOrder, self).create_procurement_purchase_order( + procurement, po_vals, line_vals) diff --git a/account_payment_purchase/tests/__init__.py b/account_payment_purchase/tests/__init__.py new file mode 100644 index 000000000..d44894fb2 --- /dev/null +++ b/account_payment_purchase/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (c) 2013-2015 Serv. Tecnol. Avanzados - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from . import test_account_payment_purchase diff --git a/account_payment_purchase/tests/test_account_payment_purchase.py b/account_payment_purchase/tests/test_account_payment_purchase.py new file mode 100644 index 000000000..7a70294ab --- /dev/null +++ b/account_payment_purchase/tests/test_account_payment_purchase.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +# (c) 2013-2015 Serv. Tecnol. Avanzados - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import fields +from openerp.tests import common + + +class TestAccountPaymentPurchase(common.TransactionCase): + def setUp(self): + super(TestAccountPaymentPurchase, self).setUp() + self.bank = self.env['res.partner.bank'].create( + {'state': 'bank', + 'bank_name': 'Test bank', + 'acc_number': '1234567890'}) + self.journal = self.env['account.journal'].create( + {'name': 'Test journal', + 'code': 'TEST', + 'type': 'general'}) + self.payment_mode = self.env['payment.mode'].create( + {'name': 'Test payment mode', + 'journal': self.journal.id, + 'bank_id': self.bank.id, + 'type': self.env.ref( + 'account_banking_payment_export.manual_bank_tranfer').id}) + self.partner = self.env['res.partner'].create( + {'name': 'Test partner', + 'supplier_payment_mode': self.payment_mode.id}) + self.purchase = self.env['purchase.order'].create( + {'partner_id': self.partner.id, + 'pricelist_id': ( + self.partner.property_product_pricelist_purchase.id), + 'payment_mode_id': self.payment_mode.id, + 'location_id': self.env['stock.location'].search([], limit=1).id, + 'invoice_method': 'order', + 'order_line': [(0, 0, {'name': 'Test line', + 'product_qty': 1.0, + 'date_planned': fields.Date.today(), + 'price_unit': 1.0})]}) + + def test_onchange_partner_id_purchase_order(self): + res = self.env['purchase.order'].onchange_partner_id(False) + self.assertEqual(res['value']['payment_mode_id'], False) + res = self.env['purchase.order'].onchange_partner_id(self.partner.id) + self.assertEqual(res['value']['payment_mode_id'], self.payment_mode.id) + + def test_purchase_order_invoicing(self): + self.purchase.signal_workflow('purchase_confirm') + self.assertEqual( + self.purchase.invoice_ids[0].payment_mode_id, self.payment_mode) + + def test_picking_from_purchase_order_invoicing(self): + 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.invoice_method = 'picking' + self.purchase.signal_workflow('purchase_confirm') + picking = self.purchase.picking_ids[0] + invoice_id = picking.action_invoice_create( + self.journal.id, type='in_invoice')[0] + invoice = self.env['account.invoice'].browse(invoice_id) + self.assertEqual(invoice.payment_mode_id, self.payment_mode) + + def test_procurement_buy_payment_mode(self): + mto_product = self.env['product.product'].create( + {'name': 'Test buy product', + 'type': 'product', + 'seller_ids': [(0, 0, {'name': self.partner.id})]}) + route = self.env.ref('purchase.route_warehouse0_buy') + rule = self.env['procurement.rule'].search( + [('route_id', '=', route.id)], limit=1) + procurement_order = self.env['procurement.order'].create( + {'product_id': mto_product.id, + 'rule_id': rule.id, + 'location_id': self.env['stock.location'].search([], limit=1).id, + 'warehouse_id': self.env['stock.warehouse'].search( + [], limit=1).id, + 'product_qty': 1, + 'product_uom': mto_product.uom_id.id, + 'name': 'Procurement order test'}) + procurement_order.run() + self.assertEqual( + procurement_order.purchase_id.payment_mode_id, self.payment_mode)