Skip to content

Commit

Permalink
[MIG] account_invoice_margin: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ljsalvatierra-factorlibre committed May 26, 2023
1 parent cd73bf4 commit b241bed
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 117 deletions.
2 changes: 1 addition & 1 deletion account_invoice_margin/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Account Invoice Margin",
"summary": "Show margin in invoices",
"version": "15.0.1.0.1",
"version": "16.0.1.0.0",
"category": "Account",
"website": "https://github.com/OCA/margin-analysis",
"author": "Tecnativa, " "GRAP, " "Odoo Community Association (OCA)",
Expand Down
4 changes: 4 additions & 0 deletions account_invoice_margin/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
* `Avoin.Systems <https://www.avoin.systems>`__:

* Nedas Žilinskas

* `Factor Libre <https://factorlibre.com>`__:

* Luis J. Salvatierra
8 changes: 6 additions & 2 deletions account_invoice_margin/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ This module allows to show sales margin in invoices.

The new information is available:

* on the account form view
* on the invoice form view

.. figure:: ../static/description/account_invoice_form.png
:scale: 80 %
:alt: Invoice Tree View

* and on the account tree view
* and on the invoice tree view

.. figure:: ../static/description/account_invoice_tree.png
:scale: 80 %
:alt: Invoice Tree View
107 changes: 22 additions & 85 deletions account_invoice_margin/tests/test_account_invoice_margin.py
Original file line number Diff line number Diff line change
@@ -1,96 +1,34 @@
# © 2016 Sergio Teruel <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields
from odoo.tests.common import Form, TransactionCase, tagged
from odoo.tests.common import Form, tagged

from odoo.addons.account.tests.common import AccountTestInvoicingCommon


@tagged("post_install", "-at_install")
class TestAccountInvoiceMargin(TransactionCase):
class TestAccountInvoiceMargin(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
super(TestAccountInvoiceMargin, cls).setUpClass()
cls.Product = cls.env["product.template"]

cls.journal = cls.env["account.journal"].create(
{"name": "Test journal", "type": "sale", "code": "TEST_J"}
)
cls.account_type = cls.env["account.account.type"].create(
{"name": "Test account type", "type": "other", "internal_group": "income"}
)
cls.account = cls.env["account.account"].create(
{
"name": "Test account",
"code": "TEST_A",
"user_type_id": cls.account_type.id,
"reconcile": True,
}
)
cls.partner = cls.env["res.partner"].create(
{"name": "Test partner", "customer_rank": 1, "is_company": True}
)
cls.partner.property_account_receivable_id = cls.account
cls.product_categ = cls.env["product.category"].create(
{"name": "Test category"}
)

cls.product = cls.env["product.product"].create(
{
"name": "test product",
"categ_id": cls.product_categ.id,
"uom_id": cls.env.ref("uom.product_uom_unit").id,
"uom_po_id": cls.env.ref("uom.product_uom_unit").id,
"default_code": "test-margin",
"list_price": 200.00,
"standard_price": 100.00,
}
)
cls.product.property_account_income_id = cls.account
cls.invoice = cls.env["account.move"].create(
{
"partner_id": cls.partner.id,
"invoice_date": fields.Date.from_string("2017-06-19"),
"move_type": "out_invoice",
"currency_id": cls.env.user.company_id.currency_id.id,
"invoice_line_ids": [
(
0,
None,
{
"product_id": cls.product.id,
"product_uom_id": cls.product.uom_id.id,
"account_id": cls.product.property_account_income_id.id,
"name": "Test Margin",
"price_unit": cls.product.list_price,
"quantity": 10,
"purchase_price": cls.product.standard_price,
},
)
],
}
cls.product_a.lst_price = 200
cls.product_a.standard_price = 100
cls.invoice = cls.init_invoice(
"out_invoice",
partner=cls.partner_a,
invoice_date=fields.Date.from_string("2017-06-19"),
post=False,
products=cls.product_a,
)
cls.vendor_bill = cls.env["account.move"].create(
{
"partner_id": cls.partner.id,
"invoice_date": fields.Date.from_string("2017-06-19"),
"move_type": "in_invoice",
"currency_id": cls.env.user.company_id.currency_id.id,
"invoice_line_ids": [
(
0,
None,
{
"product_id": cls.product.id,
"product_uom_id": cls.product.uom_id.id,
"account_id": cls.product.property_account_income_id.id,
"name": "Test Margin",
"price_unit": cls.product.list_price,
"quantity": 10,
},
)
],
}
cls.invoice.invoice_line_ids.quantity = 10
cls.vendor_bill = cls.init_invoice(
"in_invoice",
partner=cls.partner_a,
invoice_date=fields.Date.from_string("2017-06-19"),
post=False,
products=cls.product_a,
)
cls.vendor_bill.invoice_line_ids.quantity = 10

def test_invoice_margin(self):
self.assertEqual(self.invoice.invoice_line_ids.purchase_price, 100.00)
Expand All @@ -108,7 +46,6 @@ def test_vendor_bill_margin(self):
def test_invoice_margin_uom(self):
inv_line = self.invoice.invoice_line_ids
inv_line.update({"product_uom_id": self.env.ref("uom.product_uom_dozen").id})
inv_line.with_context(check_move_validity=False)._onchange_uom_id()
self.assertEqual(inv_line.margin, 12000.00)

def test_invoice_refund(self):
Expand Down Expand Up @@ -148,10 +85,10 @@ def test_invoice_different_currency(self):
move_form = Form(
self.env["account.move"].with_context(default_move_type="out_invoice")
)
move_form.partner_id = self.partner
move_form.partner_id = self.partner_a
move_form.currency_id = currency
move_form.invoice_date = "2022-01-01"
with move_form.invoice_line_ids.new() as line_form:
line_form.product_id = self.product
line_form.product_id = self.product_a
invoice = move_form.save()
self.assertEqual(invoice.invoice_line_ids.purchase_price, 200)
77 changes: 48 additions & 29 deletions account_invoice_margin/views/account_invoice_margin_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,74 @@
<record id="invoice_margin_form_tree" model="ir.ui.view">
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field
name="groups_id"
eval="[(4, ref('account_invoice_margin.group_account_invoice_margin_security'))]"
/>
<field name="arch" type="xml">
<!-- To allow to store new fields you must add this fields to account move lines view -->
<xpath
expr="//page[@id='aml_tab']//field[@name='price_unit']"
position="after"
>
<field name="purchase_price" invisible="1" />
<field name="margin" invisible="1" />
<field name="margin_percent" invisible="1" />
</xpath>
<!-- To display new fields in invoice lines tab -->
<xpath
expr="//field[@name='invoice_line_ids']/tree/field[@name='price_unit']"
position="after"
>
<field name="purchase_price" optional="show" />
<field name="margin" optional="show" />
<field name="margin_percent" optional="show" />
<field
name="purchase_price"
optional="show"
groups="account_invoice_margin.group_account_invoice_margin_security"
/>
<field
name="margin"
optional="show"
groups="account_invoice_margin.group_account_invoice_margin_security"
/>
<field
name="margin_percent"
optional="show"
groups="account_invoice_margin.group_account_invoice_margin_security"
/>
</xpath>
<!-- Add fields to embed invoice line form view -->
<xpath
expr="//page[@id='invoice_tab']//form//field[@name='discount']"
expr="//field[@name='invoice_line_ids']/form//field[@name='discount']"
position="after"
>
<field name="purchase_price" />
<field name="margin" />
<field name="margin_percent" />
<field
name="purchase_price"
groups="account_invoice_margin.group_account_invoice_margin_security"
/>
<field
name="margin"
groups="account_invoice_margin.group_account_invoice_margin_security"
/>
<field
name="margin_percent"
groups="account_invoice_margin.group_account_invoice_margin_security"
/>
</xpath>
<field name="tax_totals_json" position="before">
<field name="margin" />
<field name="margin_percent" />
<field name="tax_totals" position="before">
<field
name="margin"
groups="account_invoice_margin.group_account_invoice_margin_security"
/>
<field
name="margin_percent"
groups="account_invoice_margin.group_account_invoice_margin_security"
/>
</field>
</field>
</record>
<record id="view_account_invoice_tree" model="ir.ui.view">
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_invoice_tree" />
<field
name="groups_id"
eval="[(4, ref('account_invoice_margin.group_account_invoice_margin_security'))]"
/>
<field name="arch" type="xml">
<field name="amount_untaxed_signed" position="before">
<field name="margin_signed" sum="Total" optional="show" />
<field name="margin_percent" optional="show" />
<field
name="margin_signed"
sum="Total"
optional="show"
groups="account_invoice_margin.group_account_invoice_margin_security"
/>
<field
name="margin_percent"
optional="show"
groups="account_invoice_margin.group_account_invoice_margin_security"
/>
</field>
</field>
</record>
Expand Down

0 comments on commit b241bed

Please sign in to comment.