Skip to content

Commit

Permalink
[14.0][MIG] account_invoice_pricelist: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hildickethan committed Sep 27, 2021
1 parent c5eb8c0 commit 2d81fdd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion account_invoice_pricelist/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{
"name": "Account - Pricelist on Invoices",
"version": "13.0.1.0.1",
"version": "14.0.1.0.0",
"summary": "Add partner pricelist on invoices",
"category": "Accounting & Finance",
"author": "GRAP," "Therp BV," "Tecnativa," "Odoo Community Association (OCA)",
Expand Down
14 changes: 6 additions & 8 deletions account_invoice_pricelist/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ def _check_currency(self):
@api.onchange("partner_id", "company_id")
def _onchange_partner_id_account_invoice_pricelist(self):
if self.is_invoice():
result = super(AccountMove, self)._onchange_partner_id()
if (
self.partner_id
and self.type in ("out_invoice", "out_refund")
and self.move_type in ("out_invoice", "out_refund")
and self.partner_id.property_product_pricelist
):
self.pricelist_id = self.partner_id.property_product_pricelist
self._set_pricelist_currency()
return result

@api.onchange("pricelist_id")
def _set_pricelist_currency(self):
Expand Down Expand Up @@ -93,10 +91,10 @@ def _onchange_uom_id(self):
price_subtotal=price_subtotal,
currency=self.move_id.company_currency_id,
)
balance = accounting_vals["debit"] - accounting_vals["credit"]
price_unit = sel._get_fields_onchange_balance(balance=balance).get(
"price_unit", price_unit
)
amount_currency = accounting_vals["amount_currency"]
price_unit = sel._get_fields_onchange_balance(
amount_currency=amount_currency
).get("price_unit", price_unit)
sel.with_context(check_move_validity=False).update(
{"price_unit": price_unit}
)
Expand All @@ -118,7 +116,7 @@ def _get_real_price_currency(self, product, rule_id, qty, uom, pricelist_id):
):
price, rule_id = pricelist_item.base_pricelist_id.with_context(
uom=uom.id
).get_product_price_rule(product, qty, self.order_id.partner_id)
).get_product_price_rule(product, qty, self.move_id.partner_id)
pricelist_item = PricelistItem.browse(rule_id)

if pricelist_item.base == "standard_price":
Expand Down
19 changes: 18 additions & 1 deletion account_invoice_pricelist/tests/test_account_move_pricelist.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import hashlib
import inspect

from odoo.tests import common

from odoo.addons.sale.models.sale import SaleOrderLine as upstream

# if this hash fails then the original function it was copied from
# needs to be checked to see if there are any major changes that
# need to be updated in this module's _get_real_price_currency

VALID_HASHES = ["7c0bb27c20598327008f81aee58cdfb4"]


class TestAccountMovePricelist(common.SavepointCase):
@classmethod
Expand Down Expand Up @@ -193,7 +204,7 @@ def setUpClass(cls):
cls.invoice = cls.AccountMove.create(
{
"partner_id": cls.partner.id,
"type": "out_invoice",
"move_type": "out_invoice",
"invoice_line_ids": [
(
0,
Expand Down Expand Up @@ -299,3 +310,9 @@ def test_account_invoice_fixed_pricelist_without_discount_secondary_currency(sel
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertAlmostEqual(invoice_line.price_unit, 65.41)
self.assertEqual(invoice_line.discount, 8.27)

def test_upstream_file_hash(self):
"""Test that copied upstream function hasn't received fixes"""
func = inspect.getsource(upstream._get_real_price_currency).encode()
func_hash = hashlib.md5(func).hexdigest()
self.assertIn(func_hash, VALID_HASHES)
10 changes: 5 additions & 5 deletions account_invoice_pricelist/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
type="object"
name="button_update_prices_from_pricelist"
string="Update prices"
attrs="{'invisible': ['|', '|', ('pricelist_id', '=', False), ('state', 'not in', ['draft']), ('type', 'not in', ['out_invoice', 'out_refund', 'in_invoice', 'in_refund'])]}"
attrs="{'invisible': ['|', '|', ('pricelist_id', '=', False), ('state', 'not in', ['draft']), ('move_type', 'not in', ['out_invoice', 'out_refund', 'in_invoice', 'in_refund'])]}"
help="Update price in lines from the pricelist"
/>
</button>
Expand All @@ -19,12 +19,12 @@
name="attrs"
>{'readonly': [('pricelist_id', '!=', False)]}</attribute>
</field>
<field name="journal_id" position="after">
<xpath expr="//div[field[@name='journal_id']]" position="after">
<field
name="pricelist_id"
attrs="{'invisible': [('type', 'not in', ['out_invoice', 'out_refund', 'in_invoice', 'in_refund'])]}"
attrs="{'invisible': [('move_type', 'not in', ['out_invoice', 'out_refund', 'in_invoice', 'in_refund'])]}"
/>
</field>
</xpath>
</field>
</record>
<record id="account_invoice_filter_inherit_account_pricelist" model="ir.ui.view">
Expand All @@ -39,7 +39,7 @@
string="Pricelist"
name="pricelist"
context="{'group_by':'pricelist_id'}"
invisible="context.get('type', '') not in ['out_invoice', 'out_refund']"
invisible="context.get('move_type', '') not in ['out_invoice', 'out_refund']"
/>
<separator />
</xpath>
Expand Down

0 comments on commit 2d81fdd

Please sign in to comment.