mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
MIG account_invoice_margin to 12.0
This commit is contained in:
committed by
Bhoomi Vaishnani
parent
164dfebfdd
commit
41c3f8f5e4
@@ -1,7 +1,7 @@
|
||||
{
|
||||
'name': 'Invoice Margin',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'version': '11.0.1.0.0',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Accounting',
|
||||
'sequence': 95,
|
||||
'summary': 'Invoices include margin calculation.',
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user