[FIX] purchase_requisition: compute taxes for alternative PO creation
Steps to reproduce: - Create a request for quotation for a product with set vendor Taxes - Create an alternative purchase order from that RFQ with Copy Product Current Behavior: The purchase order line of the PO associated with the created alternative does not compute the taxes. Expected behavior: The taxes should be computed in the same way as if the PO was created manually and then linked to the alternatives. Cause of the issue: When creating a PO manually, the taxes of each purchase order line are computed when the product is set during the call of the `onchange_product_id` onchange method: https://github.com/odoo/odoo/blob/64c13193ae0fe23eb1b426f5bbcd8531e9a40967/addons/purchase/models/purchase.py#L1221 https://github.com/odoo/odoo/blob/7ed0a773b6e0711b127f236ce665c35202d973bc/addons/purchase/models/purchase.py#L1055-L1061 By contrast, PO created from the `action_create_alternative` generate each `purchase.order.line` using `Command.create`. Therefore these lines will not trigger the onchange method and their taxes will not be computed. Fix: To KISS, we compute the taxes of each line just after the creation of the record using the `_compute_tax_id` method. opw-3750719 closes odoo/odoo#158300 X-original-commit: 15799594bda41bdb4b65387aa5f0d46482cb91c1 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -487,3 +487,25 @@ class TestPurchaseRequisition(TestPurchaseRequisitionCommon):
|
||||
self.bo_requisition.company_id = new_company
|
||||
self.bo_requisition.action_in_progress()
|
||||
self.assertTrue(self.bo_requisition.name.startswith("REQ_"))
|
||||
|
||||
def test_taxes_for_alternative_po(self):
|
||||
"""
|
||||
Check that PO lines of PO generated by alternative compute taxes
|
||||
"""
|
||||
product = self.product_13
|
||||
vendor = self.res_partner_1
|
||||
po_form = Form(self.env['purchase.order'])
|
||||
po_form.partner_id = vendor
|
||||
with po_form.order_line.new() as line:
|
||||
line.product_id = product
|
||||
line.product_qty = 1
|
||||
orig_po = po_form.save()
|
||||
# Creates an alternative PO
|
||||
action = orig_po.action_create_alternative()
|
||||
alt_po_wizard_form = Form(self.env['purchase.requisition.create.alternative'].with_context(**action['context']))
|
||||
alt_po_wizard_form.partner_id = vendor
|
||||
alt_po_wizard_form.copy_products = True
|
||||
alt_po_wizard = alt_po_wizard_form.save()
|
||||
alt_po_id = alt_po_wizard.action_create_alternative()['res_id']
|
||||
alt_po = self.env['purchase.order'].browse(alt_po_id)
|
||||
self.assertEqual(orig_po.order_line.taxes_id, alt_po.order_line.taxes_id)
|
||||
|
||||
@@ -60,6 +60,7 @@ class PurchaseRequisitionCreateAlternative(models.TransientModel):
|
||||
)
|
||||
vals = self._get_alternative_values()
|
||||
alt_po = self.env['purchase.order'].with_context(origin_po_id=self.origin_po_id.id, default_requisition_id=False).create(vals)
|
||||
alt_po.order_line._compute_tax_id()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'form',
|
||||
|
||||
Reference in New Issue
Block a user