60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
from odoo.tests.common import TransactionCase
|
|
from odoo import fields
|
|
from datetime import timedelta
|
|
|
|
class TestStockBackdate(TransactionCase):
|
|
|
|
def setUp(self):
|
|
super(TestStockBackdate, self).setUp()
|
|
self.product = self.env['product.product'].create({
|
|
'name': 'Test Product Backdate',
|
|
'type': 'product',
|
|
'categ_id': self.env.ref('product.product_category_all').id,
|
|
})
|
|
# Enable automated valuation for the category if needed,
|
|
# but for simplicity we test the move date primarily.
|
|
self.product.categ_id.property_valuation = 'real_time'
|
|
self.product.categ_id.property_cost_method = 'average'
|
|
|
|
self.stock_location = self.env.ref('stock.stock_location_stock')
|
|
|
|
def test_inventory_backdate(self):
|
|
"""Test that inventory adjustment backdating works"""
|
|
backdate = fields.Datetime.now() - timedelta(days=10)
|
|
|
|
quant = self.env['stock.quant'].create({
|
|
'product_id': self.product.id,
|
|
'location_id': self.stock_location.id,
|
|
'inventory_quantity': 100,
|
|
})
|
|
|
|
# Set forced dates
|
|
quant.force_inventory_date = backdate
|
|
quant.force_valuation_date = backdate
|
|
|
|
# Apply inventory
|
|
quant.action_apply_inventory()
|
|
|
|
# Check stock move date
|
|
move = self.env['stock.move'].search([
|
|
('product_id', '=', self.product.id),
|
|
('is_inventory', '=', True)
|
|
], limit=1)
|
|
|
|
self.assertTrue(move, "Stock move should be created")
|
|
self.assertEqual(move.date, backdate, "Stock move date should be backdated")
|
|
|
|
# Check account move date if exists
|
|
if move.account_move_ids:
|
|
# Account move date is a Date field, so compare date parts
|
|
self.assertEqual(move.account_move_ids[0].date, backdate.date(), "Account move date should be backdated")
|
|
|
|
# Check valuation layer date (create_date)
|
|
svl = self.env['stock.valuation.layer'].search([
|
|
('stock_move_id', '=', move.id)
|
|
], limit=1)
|
|
|
|
if svl:
|
|
# Both are datetime now, so we can compare directly
|
|
self.assertEqual(svl.create_date, backdate, "SVL create_date should be backdated")
|