Skip to content

Commit

Permalink
[FIX] purchase_ux: do not update price when purchase is confirmed
Browse files Browse the repository at this point in the history
Esto no solo mejora usabilidad si no que tmb resuelve problema de cancel remaining.
Aprovechamos a borrar los onchange que no son necesarios (ya tiene un depends por ser computado)
Ademas mejoramos un poco la funcion para tener menos "ifs"

closes #177

Signed-off-by: Juan José Scarafía <jjs@adhoc.com.ar>
  • Loading branch information
jjscarafia committed Jan 31, 2024
1 parent c67ab89 commit 47b7409
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions purchase_ux/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,26 +226,26 @@ def action_add_all_to_invoice(self):
for rec in self:
rec.invoice_qty = (rec.qty_to_invoice + rec.invoice_qty)

@api.onchange('product_qty', 'product_uom')
def _compute_price_unit_and_date_planned_and_name(self):
res = super()._compute_price_unit_and_date_planned_and_name()

for line in self:
if not line.product_id:
continue

# if price was not computed (not seller or seller price = 0.0), then
# use standar price
if not line.price_unit:
price_unit = line.with_company(line.company_id.id).product_id.standard_price
if (price_unit and line.currency_id != line.company_id.currency_id):
price_unit = line.company_id.currency_id._convert(
price_unit, line.currency_id,
line.company_id,
line.date_order or fields.Date.today())
if (price_unit and line.product_uom and line.product_id.uom_id != line.product_uom):
price_unit = line.product_id.uom_id._compute_price(price_unit, line.product_uom)
line.price_unit = price_unit
""" Basicamente modificamos dos cosas:
a) si la compra esta confirmada y cambiamos cantidades u otro dato, que no se actualice ni precio,
ni descripcion ni nada. Esto, además de ser más lindo a nivel usabilidad resuelve problema de cancelar
remanente si el precio estaba modificado
b) if price was not computed (not seller or seller price = 0.0), then use standar price
"""
price_update_lines = self.filtered(lambda x: x.state not in ['purchase', 'done'])
res = super(PurchaseOrderLine, price_update_lines)._compute_price_unit_and_date_planned_and_name()

for line in price_update_lines.filtered(lambda x: x.product_id and not x.price_unit):
price_unit = line.with_company(line.company_id.id).product_id.standard_price
if (price_unit and line.currency_id != line.company_id.currency_id):
price_unit = line.company_id.currency_id._convert(
price_unit, line.currency_id,
line.company_id,
line.date_order or fields.Date.today())
if (price_unit and line.product_uom and line.product_id.uom_id != line.product_uom):
price_unit = line.product_id.uom_id._compute_price(price_unit, line.product_uom)
line.price_unit = price_unit
return res

@api.model_create_multi
Expand Down

0 comments on commit 47b7409

Please sign in to comment.