diff --git a/__manifest__.py b/__manifest__.py index ab99b30..86f658d 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -1,7 +1,7 @@ { "name": "Stock Inventory Backdate", - "summary": "Allow backdating of physical stock adjustments and valuations.", - "version": "17.0.1.0.0", + "summary": "Allow backdating of physical stock adjustments and valuations with date and time.", + "version": "17.0.1.1.0", "category": "Warehouse", "author": "Suherdy Yacob", "license": "AGPL-3", diff --git a/models/__pycache__/stock_move.cpython-312.pyc b/models/__pycache__/stock_move.cpython-312.pyc index 67217ab..12a09d5 100644 Binary files a/models/__pycache__/stock_move.cpython-312.pyc and b/models/__pycache__/stock_move.cpython-312.pyc differ diff --git a/models/__pycache__/stock_quant.cpython-312.pyc b/models/__pycache__/stock_quant.cpython-312.pyc index 179e6b2..a1745bf 100644 Binary files a/models/__pycache__/stock_quant.cpython-312.pyc and b/models/__pycache__/stock_quant.cpython-312.pyc differ diff --git a/models/stock_move.py b/models/stock_move.py index 76820bf..4d8562c 100644 --- a/models/stock_move.py +++ b/models/stock_move.py @@ -15,8 +15,10 @@ class StockMove(models.Model): # But account move creation usually happens in _action_done -> _create_account_move_line # which might use the move date. # Let's check if we need to update account moves. + # Account move date field is Date type, so convert datetime to date if move.account_move_ids: - move.account_move_ids.write({'date': forced_inventory_date}) + account_date = forced_inventory_date.date() if hasattr(forced_inventory_date, 'date') else forced_inventory_date + move.account_move_ids.write({'date': account_date}) return moves @@ -50,7 +52,9 @@ class StockMove(models.Model): target_date = forced_valuation_date or forced_inventory_date if target_date: - vals['date'] = target_date + # Account move date field is Date type, so convert datetime to date if needed + account_date = target_date.date() if hasattr(target_date, 'date') else target_date + vals['date'] = account_date return vals diff --git a/models/stock_quant.py b/models/stock_quant.py index cb5d0b6..e008a78 100644 --- a/models/stock_quant.py +++ b/models/stock_quant.py @@ -4,15 +4,15 @@ from odoo.exceptions import ValidationError class StockQuant(models.Model): _inherit = 'stock.quant' - force_inventory_date = fields.Date( + force_inventory_date = fields.Datetime( string="Force Inventory Date", - help="Choose a specific date for the inventory adjustment. " - "If set, the stock move will be created with this date." + help="Choose a specific date and time for the inventory adjustment. " + "If set, the stock move will be created with this date and time." ) - force_valuation_date = fields.Date( + force_valuation_date = fields.Datetime( string="Force Valuation Date", - help="Choose a specific date for the stock valuation. " - "If set, the valuation layer will be created with this date." + help="Choose a specific date and time for the stock valuation. " + "If set, the valuation layer will be created with this date and time." ) @api.model diff --git a/tests/test_stock_backdate.py b/tests/test_stock_backdate.py index 6805a2a..abd6e18 100644 --- a/tests/test_stock_backdate.py +++ b/tests/test_stock_backdate.py @@ -20,7 +20,7 @@ class TestStockBackdate(TransactionCase): def test_inventory_backdate(self): """Test that inventory adjustment backdating works""" - backdate = fields.Date.today() - timedelta(days=10) + backdate = fields.Datetime.now() - timedelta(days=10) quant = self.env['stock.quant'].create({ 'product_id': self.product.id, @@ -42,11 +42,12 @@ class TestStockBackdate(TransactionCase): ], limit=1) self.assertTrue(move, "Stock move should be created") - self.assertEqual(move.date.date(), backdate, "Stock move date should be backdated") + self.assertEqual(move.date, backdate, "Stock move date should be backdated") # Check account move date if exists if move.account_move_ids: - self.assertEqual(move.account_move_ids[0].date, backdate, "Account move date should be backdated") + # 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([ @@ -54,6 +55,5 @@ class TestStockBackdate(TransactionCase): ], limit=1) if svl: - # create_date is datetime, backdate is date. - # We check if the date part matches. - self.assertEqual(svl.create_date.date(), backdate, "SVL create_date should be backdated") + # Both are datetime now, so we can compare directly + self.assertEqual(svl.create_date, backdate, "SVL create_date should be backdated")