Skip to content

Commit

Permalink
[MIG] account_invoice_pricelist: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peluko00 committed Jul 12, 2024
1 parent 14fa4cb commit 365a034
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 18 deletions.
3 changes: 3 additions & 0 deletions account_invoice_pricelist/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ Contributors
- Alberto Martín <[email protected]>
- Nikul Chaudhary <[email protected]>
- Manuel Regidor <[email protected]>
- `APSL-Nagarro <https://www.apsl.tech>`__:

- Antoni Marroig <[email protected]>

Maintainers
-----------
Expand Down
1 change: 1 addition & 0 deletions account_invoice_pricelist/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from .hooks import pre_init_hook
5 changes: 3 additions & 2 deletions account_invoice_pricelist/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

{
"name": "Account - Pricelist on Invoices",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"summary": "Add partner pricelist on invoices",
"category": "Accounting & Finance",
"author": "GRAP," "Therp BV," "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
"license": "AGPL-3",
"depends": ["account"],
"depends": ["account", "sale_management"],
"data": ["views/account_invoice_view.xml"],
"installable": True,
"pre_init_hook": "pre_init_hook",
}
14 changes: 14 additions & 0 deletions account_invoice_pricelist/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 Studio73 - Ethan Hildick <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tools.sql import column_exists, create_column


def pre_init_hook(env):
# Speed up the installation of the module on an existing Odoo instance
# by not computing the pricelist for every invoice. Also avoids
# a possible computation error of
# computing all pricelists -> _check_currency constraint error before the
# currency can recompute itself
if not column_exists(env.cr, "account_move", "pricelist_id"):
create_column(env.cr, "account_move", "pricelist_id", "int4")
4 changes: 1 addition & 3 deletions account_invoice_pricelist/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ class AccountMove(models.Model):
pricelist_id = fields.Many2one(
comodel_name="product.pricelist",
string="Pricelist",
states={"draft": [("readonly", False)]},
compute="_compute_pricelist_id",
tracking=True,
store=True,
readonly=True,
precompute=True,
)

Expand Down Expand Up @@ -122,7 +120,7 @@ def _get_price_with_pricelist(self):
qty,
uom,
date,
target_currency=self.currency_id,
currency=self.currency_id,
)
price_unit = max(base_price, final_price)
self.with_context(
Expand Down
2 changes: 2 additions & 0 deletions account_invoice_pricelist/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
- Alberto Martín \<<[email protected]>\>
- Nikul Chaudhary \<<[email protected]>\>
- Manuel Regidor \<<[email protected]>\>
- [APSL-Nagarro](https://www.apsl.tech):
- Antoni Marroig \<<[email protected]>\>
4 changes: 4 additions & 0 deletions account_invoice_pricelist/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Alberto Martín &lt;<a class="reference external" href="mailto:alberto.martin&#64;guadaltech.es">alberto.martin&#64;guadaltech.es</a>&gt;</li>
<li>Nikul Chaudhary &lt;<a class="reference external" href="mailto:nikulchaudhary2112&#64;gmail.com">nikulchaudhary2112&#64;gmail.com</a>&gt;</li>
<li>Manuel Regidor &lt;<a class="reference external" href="mailto:manuel.regidor&#64;sygel.es">manuel.regidor&#64;sygel.es</a>&gt;</li>
<li><a class="reference external" href="https://www.apsl.tech">APSL-Nagarro</a>:<ul>
<li>Antoni Marroig &lt;<a class="reference external" href="mailto:amarroig&#64;apsl.net">amarroig&#64;apsl.net</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
13 changes: 8 additions & 5 deletions account_invoice_pricelist/tests/test_account_move_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def setUpClass(cls):
],
}
)
cls.euro_currency = cls.env["res.currency"].search([("name", "=", "EUR")])
cls.euro_currency = cls.env["res.currency"].search(
[("active", "=", False), ("name", "=", "EUR")]
)
cls.euro_currency.active = True
cls.usd_currency = cls.env["res.currency"].search([("name", "=", "USD")])
cls.sale_pricelist_with_discount_in_euros = cls.ProductPricelist.create(
{
Expand Down Expand Up @@ -280,14 +283,14 @@ def test_account_invoice_pricelist_with_discount_secondary_currency(self):
self.invoice.pricelist_id = self.sale_pricelist_with_discount_in_euros.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertAlmostEqual(invoice_line.price_unit, 58.87)
self.assertAlmostEqual(invoice_line.price_unit, 75.55)
self.assertEqual(invoice_line.discount, 0.00)

def test_account_invoice_pricelist_without_discount_secondary_currency(self):
self.invoice.pricelist_id = self.sale_pricelist_without_discount_in_euros.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertAlmostEqual(invoice_line.price_unit, 65.41)
self.assertAlmostEqual(invoice_line.price_unit, 83.94)
self.assertEqual(invoice_line.discount, 10.00)

def test_account_invoice_fixed_pricelist_with_discount_secondary_currency(self):
Expand All @@ -301,8 +304,8 @@ def test_account_invoice_fixed_pricelist_without_discount_secondary_currency(sel
self.invoice.pricelist_id = self.sale_pricelist_fixed_wo_disc_euros.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertAlmostEqual(invoice_line.price_unit, 65.41)
self.assertEqual(invoice_line.discount, 8.27)
self.assertAlmostEqual(invoice_line.price_unit, 83.94)
self.assertEqual(invoice_line.discount, 28.52)

def test_check_currency(self):
with self.assertRaises(UserError):
Expand Down
13 changes: 5 additions & 8 deletions account_invoice_pricelist/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,21 @@
name="button_update_prices_from_pricelist"
groups="product.group_product_pricelist"
string="Update prices"
attrs="{'invisible': ['|', '|', ('pricelist_id', '=', False), ('state', 'not in', ['draft']), ('move_type', 'not in', ['out_invoice', 'out_refund'])]}"
invisible="not pricelist_id or state != 'draft' or move_type not in ['out_invoice', 'out_refund']"
help="Update price in lines from the pricelist"
/>
</button>
<xpath
expr="//group[@id='header_right_group']//field[@name='currency_id']"
position="attributes"
>
<attribute
name="attrs"
>{'readonly': [('pricelist_id', '!=', False)]}</attribute>
<attribute name="readonly">pricelist_id</attribute>
</xpath>
<xpath
expr="//group[@id='header_right_group']/field[@name='currency_id']"
position="attributes"
>
<attribute
name="attrs"
>{'readonly': [('pricelist_id', '!=', False)]}</attribute>
<attribute name="readonly">pricelist_id</attribute>
</xpath>
<xpath expr="//div[field[@name='journal_id']]" position="after">
<field
Expand All @@ -38,8 +34,9 @@
/>
<field
name="pricelist_id"
readonly="state != 'draft'"
groups="product.group_product_pricelist"
attrs="{'invisible': [('move_type', 'not in', ['out_invoice', 'out_refund'])]}"
invisible="move_type not in ['out_invoice', 'out_refund']"
/>
</xpath>
</field>
Expand Down

0 comments on commit 365a034

Please sign in to comment.