[FIX] stock_account, purchase_stock: bill price change fix
Before this commit, if a user creates a bill from a PO and confirms it. A stock valuation layer is created. if the user sets the bill to drafts and changes the product price. a new layer corrects the difference. if the user does it again, the new layer ignores the previous correction layers, resulting in wrong valuation. This commit hides the 'Reset to Draft' button when there are correction layers found. closes odoo/odoo#103347 X-original-commit: d3d41c7679f9068a7b986925b15d0d7670233bfc Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
@@ -11,6 +11,15 @@ class AccountMove(models.Model):
|
||||
stock_move_id = fields.Many2one('stock.move', string='Stock Move', index='btree_not_null')
|
||||
stock_valuation_layer_ids = fields.One2many('stock.valuation.layer', 'account_move_id', string='Stock Valuation Layer')
|
||||
|
||||
def _compute_show_reset_to_draft_button(self):
|
||||
for move in self:
|
||||
for line in move.line_ids:
|
||||
# if a line has correction layers hide the 'Reset to Darft' button
|
||||
if line._get_stock_valuation_layers(move).stock_valuation_layer_ids.filtered('account_move_line_id'):
|
||||
move.show_reset_to_draft_button = False
|
||||
return
|
||||
super()._compute_show_reset_to_draft_button()
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# OVERRIDE METHODS
|
||||
# -------------------------------------------------------------------------
|
||||
@@ -293,7 +302,6 @@ class AccountMoveLine(models.Model):
|
||||
price_unit /= prec
|
||||
layers_price_unit = line._get_stock_valuation_layers_price_unit(layers)
|
||||
layers_to_correct = line._get_stock_layer_price_difference(layers, layers_price_unit, price_unit)
|
||||
|
||||
svl_vals_list += line._prepare_in_invoice_svl_vals(layers_to_correct)
|
||||
return self.env['stock.valuation.layer'].sudo().create(svl_vals_list)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user