-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] account_invoice_supplierinfo_update_standard_price: Migration t…
…o 16.0 (from 12.0)
- Loading branch information
1 parent
938806a
commit f48db32
Showing
13 changed files
with
231 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
account_invoice_supplierinfo_update_standard_price/demo/product_product.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) | ||
@author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
--> | ||
<odoo> | ||
|
||
<record id="transport_costs_product" model="product.product"> | ||
<field name="name">Demo Transport costs</field> | ||
<field name="categ_id" ref="product.product_category_all"/> | ||
<field name="uom_id" ref="uom.product_uom_unit"/> | ||
<field name="is_impact_standard_price" eval="True"/> | ||
</record> | ||
|
||
</odoo> |
4 changes: 2 additions & 2 deletions
4
account_invoice_supplierinfo_update_standard_price/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from . import account_invoice | ||
from . import account_invoice_line | ||
from . import account_move | ||
from . import account_move_line | ||
from . import product_template |
69 changes: 0 additions & 69 deletions
69
account_invoice_supplierinfo_update_standard_price/models/account_invoice_line.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
account_invoice_supplierinfo_update_standard_price/models/account_move_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright (C) 2018-Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import _, models | ||
from odoo.exceptions import Warning as UserError | ||
from odoo.tools.float_utils import float_compare | ||
|
||
|
||
class AccountMoveLine(models.Model): | ||
_inherit = "account.move.line" | ||
|
||
def _get_standard_price(self): | ||
self.ensure_one() | ||
if not self.product_id: | ||
return 0 | ||
|
||
if self.move_id.product_expense_total == 0: | ||
raise UserError( | ||
_("We can't check prices for a invoice whose total is null") | ||
) | ||
line_shared_cost = self.move_id.distributed_expense_total * ( | ||
self.price_subtotal / self.move_id.product_expense_total | ||
) | ||
|
||
if self.quantity: | ||
line_shared_cost_per_unit = line_shared_cost / self.quantity | ||
else: | ||
line_shared_cost_per_unit = 0 | ||
uom = self.product_uom_id or self.product_id.uom_id | ||
return self.move_id.currency_id.round( | ||
uom._compute_price( | ||
line_shared_cost_per_unit | ||
+ ( | ||
self.price_unit | ||
* (1 - self.discount1 / 100) | ||
* (1 - self.discount2 / 100) | ||
* (1 - self.discount3 / 100) | ||
), | ||
self.product_id.uom_id, | ||
) | ||
) | ||
|
||
def _is_correct_price(self, supplierinfo): | ||
self.ensure_one() | ||
DecimalPrecision = self.env["decimal.precision"] | ||
res = super()._is_correct_price(supplierinfo) | ||
if not self.product_id: | ||
return res | ||
|
||
return res and not float_compare( | ||
self.product_id.standard_price, | ||
self._get_standard_price(), | ||
precision_digits=DecimalPrecision.precision_get("Product Price"), | ||
) | ||
|
||
def _prepare_supplier_wizard_line(self, supplierinfo): | ||
res = super()._prepare_supplier_wizard_line(supplierinfo) | ||
if self.product_id: | ||
res.update( | ||
{ | ||
"current_standard_price": self.product_id.standard_price, | ||
"new_standard_price": self._get_standard_price(), | ||
} | ||
) | ||
return res |
1 change: 1 addition & 0 deletions
1
account_invoice_supplierinfo_update_standard_price/tests/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_module |
105 changes: 105 additions & 0 deletions
105
account_invoice_supplierinfo_update_standard_price/tests/test_module.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Copyright 2018 - Today: GRAP (http://www.grap.coop) | ||
# Copyright Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from odoo.tests import Form, tagged | ||
|
||
from odoo.addons.account_invoice_supplierinfo_update_triple_discount.tests import ( | ||
test_module, | ||
) | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestModuleStandardPrice(test_module.TestModuleTripleDiscount): | ||
@classmethod | ||
def setUpClass(cls, chart_template_ref=None): | ||
super().setUpClass(chart_template_ref=chart_template_ref) | ||
|
||
cls.product_d = cls.env["product.product"].create( | ||
{ | ||
"name": "product_d", | ||
"uom_id": cls.env.ref("uom.product_uom_unit").id, | ||
"uom_po_id": cls.env.ref("uom.product_uom_unit").id, | ||
"lst_price": 10.0, | ||
"standard_price": 0.0, | ||
"property_account_income_id": cls.copy_account( | ||
cls.company_data["default_account_revenue"] | ||
).id, | ||
"property_account_expense_id": cls.copy_account( | ||
cls.company_data["default_account_expense"] | ||
).id, | ||
"taxes_id": [], | ||
"supplier_taxes_id": [], | ||
"is_impact_standard_price": True, | ||
} | ||
) | ||
|
||
def _add_impact_standard_price_line(self): | ||
with Form(self.invoice) as invoice_form: | ||
with invoice_form.invoice_line_ids.new() as line_form: | ||
line_form.product_id = self.product_d | ||
line_form.quantity = 15 | ||
line_form.price_unit = 1 | ||
line_form.tax_ids.clear() | ||
invoice_form.save() | ||
|
||
self.line_d = self.invoice.invoice_line_ids.filtered( | ||
lambda x: x.product_id == self.product_d | ||
) | ||
|
||
# configuration | ||
# line_a (4000 $) | ||
# - quantity: 10 // price_unit: 400 // uom_id: uom_unit | ||
|
||
# line_b (5.6 $) | ||
# - quantity: 1 // price_unit: 10 // uom_id: uom_dozen | ||
# - discount1: 10.0 // discount2: 20.0 // discount3: 30.0 | ||
|
||
# line_without_product (35 $) | ||
# - quantity: 1 // price_unit: 35 | ||
|
||
# line_d (15 $) | ||
# - quantity: 15 // price_unit: 1 | ||
|
||
# PRODUCT TOTAL: 4000 + 5.6 + 35 = 4040.60 | ||
|
||
def test_invoice_new_field_computation(self): | ||
self.assertAlmostEqual(self.invoice.product_expense_total, 4000 + 5.6 + 35) | ||
self.assertAlmostEqual(self.invoice.distributed_expense_total, 0) | ||
self._add_impact_standard_price_line() | ||
self.assertAlmostEqual(self.invoice.distributed_expense_total, 15) | ||
|
||
def test_supplierinfo_update_standard_price_without_distributed(self): | ||
vals_wizard = self.invoice.check_supplierinfo().get("context", {}) | ||
|
||
line_ids = vals_wizard.get("default_line_ids", {}) | ||
|
||
self.assertEqual(len(line_ids), 2) | ||
self.assertAlmostEqual(line_ids[0][2]["new_standard_price"], 4000.0 / 10) | ||
self.assertAlmostEqual(line_ids[1][2]["new_standard_price"], 5.6) | ||
|
||
# Create and launch update process | ||
wizard = self.WizardUpdateSupplierinfo.create( | ||
{"line_ids": line_ids, "invoice_id": self.invoice.id} | ||
) | ||
|
||
wizard.update_supplierinfo() | ||
|
||
self.assertAlmostEqual(self.product_a.standard_price, 4000.0 / 10) | ||
self.assertAlmostEqual(self.product_b.standard_price, 5.6) | ||
|
||
def test_supplierinfo_update_standard_price_with_distributed(self): | ||
self._add_impact_standard_price_line() | ||
|
||
vals_wizard = self.invoice.check_supplierinfo().get("context", {}) | ||
|
||
line_ids = vals_wizard.get("default_line_ids", {}) | ||
|
||
self.assertEqual(len(line_ids), 2) | ||
self.assertAlmostEqual( | ||
line_ids[0][2]["new_standard_price"], | ||
self.invoice.currency_id.round((4000.0 + 15 * 4000 / 4040.60) / 10), | ||
) | ||
self.assertAlmostEqual( | ||
line_ids[1][2]["new_standard_price"], | ||
self.invoice.currency_id.round(5.6 + 15 * 5.6 / 4040.60), | ||
) |
27 changes: 0 additions & 27 deletions
27
account_invoice_supplierinfo_update_standard_price/views/view_account_invoice.xml
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
account_invoice_supplierinfo_update_standard_price/views/view_account_move.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) | ||
@author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
--> | ||
<odoo> | ||
|
||
<record id="view_account_move_form" model="ir.ui.view"> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_move_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='tax_totals']" position="before"> | ||
<group class="oe_subtotal_footer oe_right" attrs="{'invisible': [ | ||
'|', | ||
('move_type', 'not in', ('in_invoice', 'in_refund', 'in_receipt')), | ||
('distributed_expense_total', '=', 0), | ||
]}"> | ||
<field name="product_expense_total" /> | ||
<field name="distributed_expense_total" /> | ||
</group> | ||
|
||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
Oops, something went wrong.