From 41c3f8f5e42d6eb79b4aa1cfd033802810f83caa Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Mon, 8 Apr 2019 14:39:12 -0700 Subject: [PATCH] MIG `account_invoice_margin` to 12.0 --- account_invoice_margin/__manifest__.py | 2 +- account_invoice_margin/models/account_invoice.py | 4 ++-- account_invoice_margin/tests/test_invoice_margin.py | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/account_invoice_margin/__manifest__.py b/account_invoice_margin/__manifest__.py index 3fe289bf..562b81e0 100755 --- a/account_invoice_margin/__manifest__.py +++ b/account_invoice_margin/__manifest__.py @@ -1,7 +1,7 @@ { 'name': 'Invoice Margin', 'author': 'Hibou Corp. ', - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'category': 'Accounting', 'sequence': 95, 'summary': 'Invoices include margin calculation.', diff --git a/account_invoice_margin/models/account_invoice.py b/account_invoice_margin/models/account_invoice.py index b0ff750d..295d68f7 100644 --- a/account_invoice_margin/models/account_invoice.py +++ b/account_invoice_margin/models/account_invoice.py @@ -19,7 +19,7 @@ class AccountInvoiceLine(models.Model): purchase_price = product_id.uom_id._compute_price(purchase_price, product_uom_id) ctx = self.env.context.copy() ctx['date'] = invoice_id.date if invoice_id.date else fields.Date.context_today(invoice_id) - price = frm_cur.with_context(ctx).compute(purchase_price, to_cur, round=False) + price = frm_cur.with_context(ctx)._convert(purchase_price, to_cur, invoice_id.company_id, ctx['date'], round=False) return price @api.onchange('product_id', 'uom_id') @@ -42,7 +42,7 @@ class AccountInvoiceLine(models.Model): if line.product_id and not price: date = line.invoice_id.date if line.invoice_id.date else fields.Date.context_today(line.invoice_id) from_cur = line.invoice_id.company_currency_id.with_context(date=date) - price = from_cur.compute(line.product_id.standard_price, currency, round=False) + price = from_cur._convert(line.product_id.standard_price, currency, line.company_id, date, round=False) line.margin = currency.round(line.price_subtotal - (price * line.quantity)) diff --git a/account_invoice_margin/tests/test_invoice_margin.py b/account_invoice_margin/tests/test_invoice_margin.py index 0fc6fb79..27945325 100644 --- a/account_invoice_margin/tests/test_invoice_margin.py +++ b/account_invoice_margin/tests/test_invoice_margin.py @@ -1,4 +1,6 @@ from odoo.addons.sale_margin.tests.test_sale_margin import TestSaleMargin +from datetime import datetime + class TestInvoiceMargin(TestSaleMargin): @@ -10,10 +12,11 @@ class TestInvoiceMargin(TestSaleMargin): """ Test the sale_margin module in Odoo. """ # Create a sales order for product Graphics Card. sale_order_so11 = self.SaleOrder.create({ + 'date_order': datetime.today(), 'name': 'Test_SO011', 'order_line': [ (0, 0, { - 'name': '[CARD] Graphics Card', + 'name': '[CARD] Individual Workplace', 'purchase_price': 700.0, 'price_unit': 1000.0, 'product_uom': self.product_uom_id, @@ -26,8 +29,7 @@ class TestInvoiceMargin(TestSaleMargin): 'purchase_price': 700.0, 'product_uom_qty': 10.0, 'state': 'draft', - 'product_id': self.product_id}) - ], + 'product_id': self.product_id})], 'partner_id': self.partner_id, 'partner_invoice_id': self.partner_invoice_address_id, 'partner_shipping_id': self.partner_invoice_address_id, @@ -37,6 +39,8 @@ class TestInvoiceMargin(TestSaleMargin): # Verify that margin field gets bind with the value. self.assertEqual(sale_order_so11.margin, 6000.00, "Sales order margin should be 6000.00") + sale_order_so11.order_line.write({'qty_delivered': 10.0}) + # Invoice the sales order. inv_id = sale_order_so11.action_invoice_create() inv = self.AccountInvoice.browse(inv_id)