Skip to content
Snippets Groups Projects
Commit 296ec254 authored by Touati Djamel (otd)'s avatar Touati Djamel (otd) Committed by Victor Feyens
Browse files

[FIX] sale(_stock_margin): do not recompute the cost when the SO is sent


Steps to reproduce the bug:
- Create a storable product “P1”:
    - change the cost to $20
    - product category > costing method > standard price
- Create a SO:
    - Add the product “P1”
    - Change the cost from $20 to $10
    - Save
    - Sent the quotation by Email

Problem:
The `purchase_price` is recomputed and changes back to the original value.

When the quotation is sent, the state of the order lines change,
marking the field `qty_delivered_method` to be recomputed, but also
other computed fields depending on it, including the purchase_price
(because of the dependency added in sale_timesheet_margin).

To avoid this unexpected recomputation, we remove the useless
dependency on the `state` for the field `qty_delivered_method`.
There is no reference/check on the state in the method
_compute_qty_delivered_method or any of its overrides and
therefore the field should not be necessary in the compute
dependencies.

opw-2994136

closes odoo/odoo#103739

Signed-off-by: default avatarVictor Feyens (vfe) <vfe@odoo.com>
parent 2a3e1ed1
No related branches found
No related tags found
No related merge requests found
......@@ -320,7 +320,7 @@ class SaleOrderLine(models.Model):
for line in self:
line.product_uom_readonly = line.state in ['sale', 'done', 'cancel']
@api.depends('state', 'is_expense')
@api.depends('is_expense')
def _compute_qty_delivered_method(self):
""" Sale module compute delivered qty for product [('type', 'in', ['consu']), ('service_type', '=', 'manual')]
- consu + expense_policy : analytic (sum of analytic unit_amount)
......
......@@ -3,10 +3,11 @@
from odoo import fields
from odoo.tests.common import Form
from odoo.tests import Form, tagged
from odoo.addons.stock_account.tests.test_stockvaluationlayer import TestStockValuationCommon
@tagged('post_install', '-at_install')
class TestSaleStockMargin(TestStockValuationCommon):
@classmethod
......@@ -295,3 +296,21 @@ class TestSaleStockMargin(TestStockValuationCommon):
self.assertEqual(sol.purchase_price, 100)
self.assertEqual(sol.margin, 100)
def test_purchase_price_changes(self):
so = self._create_sale_order()
product = self._create_product()
product.categ_id.property_cost_method = 'standard'
product.standard_price = 20
self._create_sale_order_line(so, product, 1, product.list_price)
so_form = Form(so)
with so_form.order_line.edit(0) as line:
line.purchase_price = 15
so = so_form.save()
email_act = so.action_quotation_send()
email_ctx = email_act.get('context', {})
so.with_context(**email_ctx).message_post_with_template(email_ctx.get('default_template_id'))
self.assertEqual(so.state, 'sent')
self.assertEqual(so.order_line[0].purchase_price, 15)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment