you can achieve it using code. Here's an example of how you can delete these entries programmatically:
# Import necessary models
from odoo import api, models
class StockValuationEntryDeletion(models.Model):
_inherit = 'stock.valuation.layer'
@api.model
def delete_entries(self, product_id):
# Retrieve the Stock Valuation Layer entries for the given product
valuation_entries = self.search([('product_id', '=', product_id)])
# Delete the Stock Valuation Layer entries
valuation_entries.unlink()
class JournalEntryDeletion(models.Model):
_inherit = 'account.move'
@api.model
def delete_entries(self, product_id):
# Retrieve the Journal entries for the given product
journal_entries = self.env['account.move'].search([('stock_valuation_layer_ids.product_id', '=', product_id)])
# Delete the Journal entries
journal_entries.unlink()
You can then use these methods to delete the entries. For example:
product_id = 123 # Replace with the actual product ID
StockValuationEntryDeletion.delete_entries(product_id)
JournalEntryDeletion.delete_entries(product_id)
Make sure you run this code with the necessary access rights and proper validation to ensure the correct entries are deleted. It's recommended to test this code in a development environment first and take proper backups before running it in a production environment.
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