Skip to content

Commit

Permalink
[MIG] account_invoice_prices_update: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximiliano Mezzavilla committed Feb 17, 2023
1 parent 4ea927e commit 714c830
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions account_invoice_prices_update/__manifest__.py
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Account Invoice Prices Update',
'version': "15.0.1.0.0",
'version': "16.0.1.0.0",
'author': 'ADHOC SA',
'license': 'AGPL-3',
'category': 'Accounting & Finance',
Expand All @@ -32,5 +32,5 @@
'views/account_move_views.xml',
'security/ir.model.access.csv',
],
'installable': False,
'installable': True,
}
Expand Up @@ -26,7 +26,7 @@ def _get_display_price_and_discount(self, product, line):
discount = 0.0
if self.pricelist_id.discount_policy == 'with_discount':
return product.with_context(
pricelist=self.pricelist_id.id).price, discount
pricelist=self.pricelist_id.id)._get_contextual_price(), discount
partner = line.move_id.partner_id
product_context = dict(
self.env.context, partner_id=partner.id,
Expand Down Expand Up @@ -64,21 +64,18 @@ def update_prices(self):
uom=line.product_uom_id.id,
fiscal_position=self.env.context.get('fiscal_position')
)
price = line.product_id._get_contextual_price()
price, discount = self._get_display_price_and_discount(product, line)
line.write({
'price_unit': price,
'discount': discount,
})
# we needed run this "onchanges" because it's necessary to complete the correct values after the
# write the price and discount in the line.
line._onchange_balance()
line._onchange_mark_recompute_taxes()
line.move_id._onchange_invoice_line_ids()

invoice.message_post(body='The pricelist is now: %s' % self.pricelist_id.display_name)
return True

def _get_real_price_currency(
self, product, rule_id, qty, uom, pricelist_id, partner):
self, product, rule_id, qty, uom, partner):
"""Retrieve the price before applying the pricelist
:param obj product: object of current product record
:parem float qty: total quantity of product
Expand All @@ -88,7 +85,7 @@ def _get_real_price_currency(
:param integer pricelist_id: pricelist id of invoice
:param obj partner: partner id of invoice"""
PricelistItem = self.env['product.pricelist.item']
field_name = 'lst_price'
product_disc = product['lst_price']
currency_id = None
product_currency = product.currency_id
active_id = self._context.get('active_id', False)
Expand All @@ -108,11 +105,11 @@ def _get_real_price_currency(
pricelist_item = PricelistItem.browse(rule_id)

if pricelist_item.base == 'standard_price':
field_name = 'standard_price'
product_disc = product['standard_price']
product_currency = product.cost_currency_id
elif pricelist_item.base == 'pricelist' and\
pricelist_item.base_pricelist_id:
field_name = 'price'
product_disc = product._get_contextual_price()
product = product.with_context(
pricelist=pricelist_item.base_pricelist_id.id)
product_currency = pricelist_item.base_pricelist_id.currency_id
Expand All @@ -137,4 +134,4 @@ def _get_real_price_currency(
else:
uom_factor = 1.0

return product[field_name] * uom_factor * cur_factor, currency_id.id
return product_disc * uom_factor * cur_factor, currency_id.id
Expand Up @@ -6,9 +6,9 @@
<field name="model">account.invoice.prices_update.wizard</field>
<field name="arch" type="xml">
<form string="Update Prices Wizard">
<group>
<div>
<field name="pricelist_id" options="{'no_create': True,'no_open': True}"/>
</group>
</div>
<footer>
<button string="Update Prices" name="update_prices" type="object" class="oe_highlight"/>
or
Expand Down

0 comments on commit 714c830

Please sign in to comment.