Skip to content

Commit db9fc75

Browse files
migration-bot-adhocmatiasperalta1
authored andcommitted
[MIG] product_planned_price: Migration to 19.0
1 parent 94397a8 commit db9fc75

File tree

6 files changed

+39
-25
lines changed

6 files changed

+39
-25
lines changed

product_planned_price/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
##############################################################################
2020
{
2121
"name": "Product Planned Price",
22-
"version": "18.0.1.1.0",
22+
"version": "19.0.1.0.0",
2323
"category": "Product",
2424
"sequence": 14,
2525
"author": "ADHOC SA,Odoo Community Association (OCA)",
@@ -39,7 +39,7 @@
3939
"demo": [
4040
"demo/product_product_demo.xml",
4141
],
42-
"installable": False,
42+
"installable": True,
4343
"auto_install": False,
4444
"application": False,
4545
}

product_planned_price/demo/product_product_demo.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
<odoo noupdate="1">
33
<record id="computed_manual" model="product.product">
44
<field name="name">Computed Manual Product</field>
5-
<field name="categ_id" ref="product.product_category_4"/>
65
<field name="standard_price">20.5</field>
76
<field name="computed_list_price_manual">100</field>
87
<field name="list_price_type">manual</field>
98
<field name="type">service</field>
109
</record>
1110
<record id="computed_by_margin" model="product.product">
1211
<field name="name">Computed by Margin Product</field>
13-
<field name="categ_id" ref="product.product_category_4"/>
1412
<field name="replenishment_base_cost">50</field>
1513
<field name="replenishment_base_cost_currency_id" ref="base.USD"/>
1614
<field name="standard_price">60</field>
@@ -21,7 +19,6 @@
2119
</record>
2220
<record id="computed_other_currency" model="product.product">
2321
<field name="name">Computed Other Currency Product</field>
24-
<field name="categ_id" ref="product.product_category_4"/>
2522
<field name="standard_price">60</field>
2623
<field name="other_currency_list_price">100</field>
2724
<field name="other_currency_id" ref="base.USD"/>

product_planned_price/models/product_product.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ def price_compute(self, price_type, uom=False, currency=False, company=False, da
1414
be based on the planned, you can do it by sending use_planned_price
1515
in the context
1616
"""
17-
if self._context.get("use_planned_price") and price_type == "list_price":
17+
if self.env.context.get("use_planned_price") and price_type == "list_price":
1818
price_type = "computed_list_price"
1919
return super().price_compute(price_type, uom=uom, currency=currency, company=company, date=date)

product_planned_price/models/product_template.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ class ProductTemplate(models.Model):
2525
help='Planned Price. This value depends on Planned Price Type" an other parameters.',
2626
)
2727
list_price_type = fields.Selection(
28-
[("manual", "Fixed value"), ("by_margin", "By Margin"), ("other_currency", "Currency exchange")],
28+
[
29+
("manual", "Fixed value"),
30+
("by_margin", "By Margin"),
31+
("other_currency", "Currency exchange"),
32+
],
2933
string="Planned Price Type",
3034
# we make it optional
3135
# required=True,
@@ -94,7 +98,10 @@ def cron_update_prices_from_planned(self, batch_size=1000):
9498
last_updated_param = self.env["ir.config_parameter"].sudo().create({"key": parameter_name, "value": "0"})
9599

96100
# Obtiene los registros ordenados por id
97-
domain = [("list_price_type", "!=", False), ("id", ">", int(last_updated_param.value))]
101+
domain = [
102+
("list_price_type", "!=", False),
103+
("id", ">", int(last_updated_param.value)),
104+
]
98105
records = self.with_context(prefetch_fields=False).search(domain, order="id asc")
99106

100107
records[:batch_size].with_context(bypass_base_automation=True)._update_prices_from_planned()
@@ -105,7 +112,8 @@ def cron_update_prices_from_planned(self, batch_size=1000):
105112
last_updated_id = 0
106113

107114
self.env.cr.execute(
108-
"UPDATE ir_config_parameter set value = %s where id = %s", (str(last_updated_id), last_updated_param.id)
115+
"UPDATE ir_config_parameter set value = %s where id = %s",
116+
(str(last_updated_id), last_updated_param.id),
109117
)
110118
# Uso directo de cr.commit(). Buscar alternativa menos riesgosa
111119
self.env.cr.commit() # pragma pylint: disable=invalid-commit
@@ -127,15 +135,16 @@ def _update_prices_from_planned(self):
127135
"""
128136
prec = self.env["decimal.precision"].precision_get("Product Price")
129137

130-
cr = self._cr
138+
cr = self.env.cr
131139
for rec in self.with_context(prefetch_fields=False).filtered(
132140
lambda x: x.list_price_type
133141
and x.computed_list_price
134142
and not float_is_zero(x.computed_list_price - x.list_price, precision_digits=prec)
135143
):
136144
# es mucho mas rapido hacerlo por sql directo
137145
cr.execute(
138-
"UPDATE product_template SET list_price=%s WHERE id=%s", (rec.computed_list_price or 0.0, rec.id)
146+
"UPDATE product_template SET list_price=%s WHERE id=%s",
147+
(rec.computed_list_price or 0.0, rec.id),
139148
)
140149
return True
141150

@@ -161,15 +170,22 @@ def _compute_computed_list_price(self):
161170
)
162171
elif rec.list_price_type == "other_currency" and rec.currency_id:
163172
computed_list_price = rec.other_currency_id.sudo()._convert(
164-
rec.other_currency_list_price, rec.currency_id, rec.main_company_id, date, round=False
173+
rec.other_currency_list_price,
174+
rec.currency_id,
175+
rec.main_company_id,
176+
date,
177+
round=False,
165178
)
166179

167180
# if product has taxes with price_include, add the tax to the
168181
# sale price
169182
inc_taxes = rec.taxes_id.filtered("price_include")
170183
if inc_taxes:
171184
computed_list_price = inc_taxes.compute_all(
172-
computed_list_price, rec.currency_id, product=rec, handle_price_include=False
185+
computed_list_price,
186+
rec.currency_id,
187+
product=rec,
188+
handle_price_include=False,
173189
)["total_included"]
174190

175191
rec.update(
@@ -184,25 +200,26 @@ def price_compute(self, price_type, uom=False, currency=False, company=False, da
184200
be based on the planned, you can do it by sending use_planned_price
185201
in the context
186202
"""
187-
if self._context.get("use_planned_price") and price_type == "list_price":
203+
if self.env.context.get("use_planned_price") and price_type == "list_price":
188204
price_type = "computed_list_price"
189205
return super().price_compute(price_type, uom=uom, currency=currency, company=company, date=date)
190206

191207
@api.onchange("list_price_type")
192208
def _compute_warnings_price(self):
193209
if self.env["res.company"].sudo().search_count([]) > 1:
194-
msg = _("The values correspond to the replenishment cost to the company: %s.", self.main_company_id.name)
195-
warnings = {
196-
"company_info": {
210+
msg = _(
211+
"The values correspond to the replenishment cost to the company: %s.",
212+
self.main_company_id.name,
213+
)
214+
warnings = [
215+
{
197216
"message": msg,
198-
"action_text": False,
199-
"action": False,
200217
"level": "info",
201218
}
202-
}
219+
]
203220
fixed = self.filtered(lambda x: x.list_price_type == "manual")
204221
# para los fixed no damos warning ya que no suma valor
205-
fixed.warnings_price = {}
222+
fixed.warnings_price = False
206223
(self - fixed).warnings_price = warnings
207224
else:
208-
self.warnings_price = {}
225+
self.warnings_price = False

product_planned_price/views/product_template_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<group name="sale" position="before">
1212
<group name="pricing">
1313
<group name="planned_price" string="Planned Price">
14-
<div class="m-0" name="warnings_price" invisible="not warnings_price">
14+
<div class="m-0" name="warnings_price" invisible="not warnings_price" colspan="2">
1515
<field name="warnings_price" class="o_field_html w-100" widget="actionable_errors"/>
1616
</div>
1717
<field name="list_price_type" string="Based on"/>

product_planned_price/wizards/product_update_from_planned_price_wizard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class ProductUpdateFromPlannedPriceWizard(models.TransientModel):
1212

1313
def confirm(self):
1414
self.ensure_one()
15-
active_ids = self._context.get("active_ids")
16-
active_model = self._context.get("active_model")
15+
active_ids = self.env.context.get("active_ids")
16+
active_model = self.env.context.get("active_model")
1717
if active_model != "product.template":
1818
raise ValidationError(_("Update from planned price must be called from product " "template"))
1919
return self.env[active_model].browse(active_ids)._update_prices_from_planned()

0 commit comments

Comments
 (0)