Skip to content

Commit

Permalink
[FIX] purchase: fallback to standard price if no pricelist
Browse files Browse the repository at this point in the history
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#157860

X-original-commit: 5b255d9
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
  • Loading branch information
HANNICHE-Walid committed Mar 18, 2024
1 parent 0f6597e commit 87f3e99
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion addons/purchase/models/purchase.py
Expand Up @@ -1448,8 +1448,9 @@ def _prepare_purchase_order_line(self, product_id, product_qty, product_uom, com
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())
Expand Down
30 changes: 30 additions & 0 deletions addons/purchase_stock/tests/test_replenish_wizard.py
Expand Up @@ -248,3 +248,33 @@ def test_chose_supplier_4(self):

self.assertEqual(last_po_id.partner_id, vendor1)
self.assertEqual(last_po_id.order_line.price_unit, 60)

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',
})]
})

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,
})
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)

0 comments on commit 87f3e99

Please sign in to comment.