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
40 changes: 24 additions & 16 deletions product_replenishment_cost/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,32 @@ def _compute_price_unit_and_date_planned_and_name(self):

@api.model
def _prepare_purchase_order_line(self, product_id, product_qty, product_uom, company_id, supplier, po):
# Para casos como cuando se viene de reabastecimientos, usamos el nuevo net_price en vez de price
# Use net_price instead of raw price (net_price includes replenishment cost rules)
res = super()._prepare_purchase_order_line(product_id, product_qty, product_uom, company_id, supplier, po)

# Check if supplier is a product.supplierinfo or res.partner
# When called from procurement, supplier is res.partner (supplier.partner_id from core)
# When called directly, supplier is product.supplierinfo
if supplier and supplier._name == "product.supplierinfo":
price_unit = (
self.env["account.tax"]._fix_tax_included_price_company(
supplier.net_price, product_id.supplier_taxes_id, self.tax_ids, company_id
)
if supplier
else 0.0
today = fields.Date.today()
# supplier can be product.supplierinfo (direct call) or res.partner (from procurement via purchase_stock)
if supplier._name == "product.supplierinfo":
seller = supplier
else:
seller = product_id.with_company(company_id)._select_seller(
partner_id=supplier,
Comment on lines +56 to +60

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

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

En _prepare_purchase_order_line, se quitó el chequeo supplier and ... y ahora se accede a supplier._name directamente. Si supplier llega como False/None (caso que antes estaba contemplado), esto va a lanzar AttributeError. Recomendación: volver a proteger el acceso (p. ej. tratar supplier falsy como “sin seller” y hacer return res o resolver el seller con _select_seller solo cuando corresponda).

Copilot uses AI. Check for mistakes.
quantity=product_qty,
date=po.date_order and po.date_order.date() or today,
uom_id=product_uom,
)
Comment on lines +54 to 64

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

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

La lógica nueva cubre explícitamente el caso en que supplier es res.partner (flujo de procurement/purchase_stock) seleccionando el seller con _select_seller, pero los tests actuales solo cubren creación de líneas que terminan pasando product.supplierinfo. Sería bueno agregar un test que invoque _prepare_purchase_order_line (o el flujo equivalente) con supplier como partner y verifique que se usa seller.net_price y conversiones de moneda/UoM cuando aplique.

Copilot generated this review using guidance from repository custom instructions.
if price_unit and supplier and po.currency_id and supplier.currency_id != po.currency_id:
price_unit = supplier.currency_id._convert(
price_unit, po.currency_id, po.company_id, po.date_order or fields.Date.today()
)
res["price_unit"] = price_unit
if not seller:
return res

tax_domain = self.env["account.tax"]._check_company_domain(company_id)
product_taxes = product_id.supplier_taxes_id.filtered_domain(tax_domain)
taxes = po.fiscal_position_id.map_tax(product_taxes)
price_unit = self.env["account.tax"]._fix_tax_included_price_company(
seller.net_price, product_taxes, taxes, company_id
)
if price_unit and po.currency_id and seller.currency_id != po.currency_id:
price_unit = seller.currency_id._convert(price_unit, po.currency_id, po.company_id, po.date_order or today)
if product_uom and seller.product_uom_id and seller.product_uom_id != product_uom:
price_unit = seller.product_uom_id._compute_price(price_unit, product_uom)
res["price_unit"] = price_unit
return res
1 change: 0 additions & 1 deletion product_replenishment_cost_stock/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import stock_rule
from . import purchase_order_line
20 changes: 0 additions & 20 deletions product_replenishment_cost_stock/models/purchase_order_line.py

This file was deleted.

3 changes: 0 additions & 3 deletions product_replenishment_cost_stock/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@ def _update_purchase_order_line(self, product_id, product_qty, product_uom, comp
price_unit, po.currency_id, po.company_id, po.date_order or fields.Date.today()
)
vals["price_unit"] = price_unit
if vals["price_unit"] == 0:
vals["price_unit"] = product_id.standard_price

return vals
Loading