Skip to content
Open
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
36 changes: 27 additions & 9 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,15 +112,15 @@ 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),
Comment on lines +115 to +116
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uso de self.env.cr.execute() con query SQL directo. Aunque los parámetros están correctamente parametrizados, se recomienda utilizar el ORM de Odoo siempre que sea posible para mayor seguridad y mantenibilidad. Considera reemplazar con last_updated_param.write({'value': str(last_updated_id)}).

Copilot uses AI. Check for mistakes.
)
# Uso directo de cr.commit(). Buscar alternativa menos riesgosa
self.env.cr.commit() # pragma pylint: disable=invalid-commit

# si setamos last updated es porque todavia quedan por procesar, volvemos a llamar al cron
if last_updated_id:
# para obtener el job_id se requiere este PR https://github.com/odoo/odoo/pull/146147
cron = self.env["ir.cron"].browse(self.env.context.get("job_id")) or self.env.ref(
cron = self.env["ir.cron"].browse(self.env.context.get("cron_id")) or self.env.ref(
"product_planned_price.ir_cron_update_price_from_planned"
)
cron._trigger()
Expand All @@ -135,7 +142,8 @@ def _update_prices_from_planned(self):
):
# 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),
Comment on lines +145 to +146
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uso de cr.execute() con query SQL directo. Aunque los parámetros están correctamente parametrizados, se recomienda utilizar el ORM de Odoo para mayor seguridad y mantenibilidad. Considera reemplazar con rec.write({'list_price': rec.computed_list_price or 0.0}).

Copilot uses AI. Check for mistakes.
)
return True

Expand All @@ -161,15 +169,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 @@ -191,7 +206,10 @@ def price_compute(self, price_type, uom=False, currency=False, company=False, da
@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)
msg = _(
"The values correspond to the replenishment cost to the company: %s.",
self.main_company_id.name,
)
warnings = {
"company_info": {
"message": msg,
Expand Down
13 changes: 9 additions & 4 deletions product_replenishment_cost/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ class ProductTemplate(models.Model):
warnings_cost = fields.Json(compute="_compute_warnings_cost")

@api.depends_context("company")
@api.depends("seller_ids.net_price", "seller_ids.currency_id", "seller_ids.company_id", "replenishment_cost_type")
@api.depends(
"seller_ids.net_price",
"seller_ids.currency_id",
"seller_ids.company_id",
"replenishment_cost_type",
)
def _compute_supplier_data(self):
"""Lo ideal seria utilizar campo related para que segun los permisos
del usuario tome el seller_id que corresponda, pero el tema es que el
Expand Down Expand Up @@ -134,14 +139,14 @@ def cron_update_cost_from_replenishment_cost(self, limit=None, company_ids=None,
else:
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),
Comment on lines +142 to +143
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uso de self.env.cr.execute() con query SQL directo. Aunque los parámetros están correctamente parametrizados, se recomienda utilizar el ORM de Odoo siempre que sea posible para mayor seguridad y mantenibilidad. Considera reemplazar con last_updated_param.write({'value': str(last_updated_id)}).

Copilot uses AI. Check for mistakes.
)
# Uso directo de cr.commit(). Buscar alternativa menos riesgosa
self.env.cr.commit() # pragma pylint: disable=invalid-commit
# si setamos last updated es porque todavia quedan por procesar, volvemos a llamar al cron
if last_updated_id:
# para obtener el job_id se requiere este PR https://github.com/odoo/odoo/pull/146147
cron = self.env["ir.cron"].browse(self.env.context.get("job_id")) or self.env.ref(
cron = self.env["ir.cron"].browse(self.env.context.get("cron_id")) or self.env.ref(
"product_replenishment_cost.ir_cron_update_cost_from_replenishment_cost"
)
cron._trigger()
Expand Down