# -*- coding: utf-8 -*- from odoo.tests import TransactionCase, tagged from odoo.fields import Date @tagged('post_install', '-at_install', 'repro_bug') class TestNoRevaluation(TransactionCase): def setUp(self): super().setUp() self.env.company.currency_id = self.env.ref('base.USD') # Create a product with automated valuation (AVCO) self.product_category = self.env['product.category'].create({ 'name': 'Test Auto Valuation', 'property_cost_method': 'average', 'property_valuation': 'real_time', }) self.product = self.env['product.product'].create({ 'name': 'Test Product', 'type': 'consu', 'is_storable': True, 'categ_id': self.product_category.id, 'standard_price': 100.0, }) # Create a vendor self.vendor = self.env['res.partner'].create({'name': 'Test Vendor'}) def test_no_revaluation_on_bill_edit(self): """ Verify that editing a vendor bill line price does NOT trigger inventory revaluation (SVL creation) or accounting entries. """ # 1. Create and Confirm PO po = self.env['purchase.order'].create({ 'partner_id': self.vendor.id, 'order_line': [(0, 0, { 'product_id': self.product.id, 'product_qty': 10.0, 'price_unit': 100.0, })], }) po.button_confirm() # 2. Receive Products picking = po.picking_ids[0] picking.button_validate() # Verify initial SVL svls = self.env['stock.valuation.layer'].search([('product_id', '=', self.product.id)]) self.assertEqual(len(svls), 1, "Should be 1 SVL for reception") initial_svl_count = len(svls) # 3. Create Vendor Bill action = po.action_create_invoice() bill = self.env['account.move'].browse(action['res_id']) bill.invoice_date = Date.today() # 4. Edit Vendor Bill Line Price (Simulate User Edit) # Change price from 100 to 120 # This triggers the write method on account.move.line line = bill.invoice_line_ids[0] line.price_unit = 120.0 # This triggers the write method # 5. Verify NO new SVL created new_svls = self.env['stock.valuation.layer'].search([('product_id', '=', self.product.id)]) self.assertEqual(len(new_svls), initial_svl_count, "No new SVL should be created after bill edit") # Verify standard price did NOT change (since no revaluation) # Note: If revaluation logic was present, it would update standard_price # However, since we expect NO revaluation, standard price might stay same or move based on other logic? # The key is checking SVL count.