I have set Costing method as average cost and Inventory Valuation as Automated, I created a landed cost the cost changes and I changed the price manually and caused a Stock Valuation Layer and Journal entries has been created,
I want to delete these entries using code how?
i created a button in landed cost to cancel i tried something like this so when i change the product price 2 entries are created one 'stock.valuation.layer' and one Journal entree
stock valuation contatins a description saying Product value manually modified from 1000 to 200
i tried it using like this
if product.cost_method == 'average':
original_price = product.standard_price
new_price = product.standard_price - line.additional_landed_cost
product.write({'standard_price': new_price})
stock_valuation_layer = self.env['stock.valuation.layer'] \
.search([('product_id', '=', product.id),
('description', '=', f'Product value manually '
f'modified (from {original_price} to {new_price})')],
limit=1)
if stock_valuation_layer:
stock_valuation_layer.account_move_id.button_draft()
stock_valuation_layer.account_move_id.sudo().unlink()
stock_valuation_layer.sudo().unlink()
This works but i want to search that stock.valuation.layer instead of seaching using description ,any other way? for this
self.env['stock.valuation.layer'] \
.search([('product_id', '=', product.id),
('description', '=', f'Product value manually '
f'modified (from {original_price} to {new_price})')],
limit=1) or should i keep it like this
ANY IDEAS