-
Notifications
You must be signed in to change notification settings - Fork 102
[FIX] _planned_price,_replenishment_cost: change job_id for cron_id #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 18.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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() | ||
|
|
@@ -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), | ||
| ) | ||
| # 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() | ||
|
|
@@ -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
|
||
| ) | ||
| return True | ||
|
|
||
|
|
@@ -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( | ||
|
|
@@ -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, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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
|
||
| ) | ||
| # 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() | ||
|
|
||
There was a problem hiding this comment.
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 conlast_updated_param.write({'value': str(last_updated_id)}).