Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions product_planned_price/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
"name": "Product Planned Price",
"version": "18.0.1.1.0",
"version": "19.0.1.0.0",
"category": "Product",
"sequence": 14,
"author": "ADHOC SA,Odoo Community Association (OCA)",
Expand All @@ -39,7 +39,7 @@
"demo": [
"demo/product_product_demo.xml",
],
"installable": False,
"installable": True,
"auto_install": False,
"application": False,
}
3 changes: 0 additions & 3 deletions product_planned_price/demo/product_product_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
<odoo noupdate="1">
<record id="computed_manual" model="product.product">
<field name="name">Computed Manual Product</field>
<field name="categ_id" ref="product.product_category_4"/>
<field name="standard_price">20.5</field>
<field name="computed_list_price_manual">100</field>
<field name="list_price_type">manual</field>
<field name="type">service</field>
</record>
<record id="computed_by_margin" model="product.product">
<field name="name">Computed by Margin Product</field>
<field name="categ_id" ref="product.product_category_4"/>
<field name="replenishment_base_cost">50</field>
<field name="replenishment_base_cost_currency_id" ref="base.USD"/>
<field name="standard_price">60</field>
Expand All @@ -21,7 +19,6 @@
</record>
<record id="computed_other_currency" model="product.product">
<field name="name">Computed Other Currency Product</field>
<field name="categ_id" ref="product.product_category_4"/>
<field name="standard_price">60</field>
<field name="other_currency_list_price">100</field>
<field name="other_currency_id" ref="base.USD"/>
Expand Down
2 changes: 1 addition & 1 deletion product_planned_price/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def price_compute(self, price_type, uom=False, currency=False, company=False, da
be based on the planned, you can do it by sending use_planned_price
in the context
"""
if self._context.get("use_planned_price") and price_type == "list_price":
if self.env.context.get("use_planned_price") and price_type == "list_price":
price_type = "computed_list_price"
return super().price_compute(price_type, uom=uom, currency=currency, company=company, date=date)
49 changes: 33 additions & 16 deletions product_planned_price/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class ProductTemplate(models.Model):
help='Planned Price. This value depends on Planned Price Type" an other parameters.',
)
list_price_type = fields.Selection(
[("manual", "Fixed value"), ("by_margin", "By Margin"), ("other_currency", "Currency exchange")],
[
("manual", "Fixed value"),
("by_margin", "By Margin"),
("other_currency", "Currency exchange"),
],
string="Planned Price Type",
# we make it optional
# required=True,
Expand Down Expand Up @@ -94,7 +98,10 @@ def cron_update_prices_from_planned(self, batch_size=1000):
last_updated_param = self.env["ir.config_parameter"].sudo().create({"key": parameter_name, "value": "0"})

# Obtiene los registros ordenados por id
domain = [("list_price_type", "!=", False), ("id", ">", int(last_updated_param.value))]
domain = [
("list_price_type", "!=", False),
("id", ">", int(last_updated_param.value)),
]
records = self.with_context(prefetch_fields=False).search(domain, order="id asc")

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

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

cr = self._cr
cr = self.env.cr
for rec in self.with_context(prefetch_fields=False).filtered(
lambda x: x.list_price_type
and x.computed_list_price
and not float_is_zero(x.computed_list_price - x.list_price, precision_digits=prec)
):
# es mucho mas rapido hacerlo por sql directo
cr.execute(
"UPDATE product_template SET list_price=%s WHERE id=%s", (rec.computed_list_price or 0.0, rec.id)
"UPDATE product_template SET list_price=%s WHERE id=%s",
(rec.computed_list_price or 0.0, rec.id),
)
return True

Expand All @@ -161,15 +170,22 @@ def _compute_computed_list_price(self):
)
elif rec.list_price_type == "other_currency" and rec.currency_id:
computed_list_price = rec.other_currency_id.sudo()._convert(
rec.other_currency_list_price, rec.currency_id, rec.main_company_id, date, round=False
rec.other_currency_list_price,
rec.currency_id,
rec.main_company_id,
date,
round=False,
)

# if product has taxes with price_include, add the tax to the
# sale price
inc_taxes = rec.taxes_id.filtered("price_include")
if inc_taxes:
computed_list_price = inc_taxes.compute_all(
computed_list_price, rec.currency_id, product=rec, handle_price_include=False
computed_list_price,
rec.currency_id,
product=rec,
handle_price_include=False,
)["total_included"]

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

@api.onchange("list_price_type")
def _compute_warnings_price(self):
if self.env["res.company"].sudo().search_count([]) > 1:
msg = _("The values correspond to the replenishment cost to the company: %s.", self.main_company_id.name)
warnings = {
"company_info": {
msg = _(
"The values correspond to the replenishment cost to the company: %s.",
self.main_company_id.name,
)
warnings = [
{
"message": msg,
"action_text": False,
"action": False,
"level": "info",
}
}
]
fixed = self.filtered(lambda x: x.list_price_type == "manual")
# para los fixed no damos warning ya que no suma valor
fixed.warnings_price = {}
fixed.warnings_price = False
(self - fixed).warnings_price = warnings
else:
self.warnings_price = {}
self.warnings_price = False
2 changes: 1 addition & 1 deletion product_planned_price/views/product_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<group name="sale" position="before">
<group name="pricing">
<group name="planned_price" string="Planned Price">
<div class="m-0" name="warnings_price" invisible="not warnings_price">
<div class="m-0" name="warnings_price" invisible="not warnings_price" colspan="2">
<field name="warnings_price" class="o_field_html w-100" widget="actionable_errors"/>
</div>
<field name="list_price_type" string="Based on"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ProductUpdateFromPlannedPriceWizard(models.TransientModel):

def confirm(self):
self.ensure_one()
active_ids = self._context.get("active_ids")
active_model = self._context.get("active_model")
active_ids = self.env.context.get("active_ids")
active_model = self.env.context.get("active_model")
if active_model != "product.template":
raise ValidationError(_("Update from planned price must be called from product " "template"))
return self.env[active_model].browse(active_ids)._update_prices_from_planned()