[FIX] purchase: fallback to standard price if no pricelist

Steps to reproduce:
- Create pricelist with an end date in the past for a stored product
- Click on manual replenishement
- The created PO will have a price of 0

Bug:
if no valid pricelist is found unit price is set to 0
product standard price is a better fallback

opw-3692985

closes odoo/odoo#158650

X-original-commit: ed106e70f908deda819007fc68feaa44074c0472
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
Walid
2024-03-22 13:02:03 +00:00
parent aef34b5594
commit c6f3ab2d41
2 changed files with 36 additions and 1 deletions
@@ -594,8 +594,9 @@ class PurchaseOrderLine(models.Model):
product_taxes = product_id.supplier_taxes_id.filtered(lambda x: x.company_id.id == company_id.id)
taxes = po.fiscal_position_id.map_tax(product_taxes)
price_unit = seller.price if seller else product_id.standard_price
price_unit = self.env['account.tax']._fix_tax_included_price_company(
seller.price, product_taxes, taxes, company_id) if seller else 0.0
price_unit, product_taxes, taxes, company_id)
if price_unit and seller 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 fields.Date.today())
@@ -417,3 +417,37 @@ class TestReplenishWizard(TestStockCommon):
})
wizard.supplier_id = supplier
self.assertEqual(fields.Datetime.from_string('2023-01-08 00:00:00'), wizard.date_planned)
def test_unit_price_expired_price_list(self):
vendor = self.env['res.partner'].create({
'name': 'Contact',
'type': 'contact',
})
product = self.env['product.product'].create({
'name': 'Product',
'standard_price': 60,
'seller_ids': [(0, 0, {
'partner_id': vendor.id,
'price': 1.0,
'date_end': '2019-01-01',
})],
'route_ids': [(6, 0, [
self.env.ref('purchase_stock.route_warehouse0_buy').id
])],
})
replenish_wizard = self.env['product.replenish'].create({
'product_id': product.id,
'product_tmpl_id': product.product_tmpl_id.id,
'product_uom_id': self.uom_unit.id,
'quantity': 1,
'warehouse_id': self.wh.id,
'route_id': self.env.ref('purchase_stock.route_warehouse0_buy').id
})
replenish_wizard.launch_replenishment()
last_po_id = self.env['purchase.order'].search([
('origin', 'ilike', '%Manual Replenishment%'),
])[-1]
self.assertEqual(last_po_id.partner_id, vendor)
self.assertEqual(last_po_id.order_line.price_unit, 60)