add time field

This commit is contained in:
admin.suherdy 2025-12-08 10:28:06 +07:00
parent bad2adb1f8
commit d4710b2562
6 changed files with 20 additions and 16 deletions

View File

@ -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",

View File

@ -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

View File

@ -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

View File

@ -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")