add time field
This commit is contained in:
parent
bad2adb1f8
commit
d4710b2562
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Stock Inventory Backdate",
|
"name": "Stock Inventory Backdate",
|
||||||
"summary": "Allow backdating of physical stock adjustments and valuations.",
|
"summary": "Allow backdating of physical stock adjustments and valuations with date and time.",
|
||||||
"version": "17.0.1.0.0",
|
"version": "17.0.1.1.0",
|
||||||
"category": "Warehouse",
|
"category": "Warehouse",
|
||||||
"author": "Suherdy Yacob",
|
"author": "Suherdy Yacob",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -15,8 +15,10 @@ class StockMove(models.Model):
|
|||||||
# But account move creation usually happens in _action_done -> _create_account_move_line
|
# But account move creation usually happens in _action_done -> _create_account_move_line
|
||||||
# which might use the move date.
|
# which might use the move date.
|
||||||
# Let's check if we need to update account moves.
|
# 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:
|
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
|
return moves
|
||||||
|
|
||||||
@ -50,7 +52,9 @@ class StockMove(models.Model):
|
|||||||
target_date = forced_valuation_date or forced_inventory_date
|
target_date = forced_valuation_date or forced_inventory_date
|
||||||
|
|
||||||
if target_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
|
return vals
|
||||||
|
|
||||||
|
|||||||
@ -4,15 +4,15 @@ from odoo.exceptions import ValidationError
|
|||||||
class StockQuant(models.Model):
|
class StockQuant(models.Model):
|
||||||
_inherit = 'stock.quant'
|
_inherit = 'stock.quant'
|
||||||
|
|
||||||
force_inventory_date = fields.Date(
|
force_inventory_date = fields.Datetime(
|
||||||
string="Force Inventory Date",
|
string="Force Inventory Date",
|
||||||
help="Choose a specific date for the inventory adjustment. "
|
help="Choose a specific date and time for the inventory adjustment. "
|
||||||
"If set, the stock move will be created with this date."
|
"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",
|
string="Force Valuation Date",
|
||||||
help="Choose a specific date for the stock valuation. "
|
help="Choose a specific date and time for the stock valuation. "
|
||||||
"If set, the valuation layer will be created with this date."
|
"If set, the valuation layer will be created with this date and time."
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class TestStockBackdate(TransactionCase):
|
|||||||
|
|
||||||
def test_inventory_backdate(self):
|
def test_inventory_backdate(self):
|
||||||
"""Test that inventory adjustment backdating works"""
|
"""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({
|
quant = self.env['stock.quant'].create({
|
||||||
'product_id': self.product.id,
|
'product_id': self.product.id,
|
||||||
@ -42,11 +42,12 @@ class TestStockBackdate(TransactionCase):
|
|||||||
], limit=1)
|
], limit=1)
|
||||||
|
|
||||||
self.assertTrue(move, "Stock move should be created")
|
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
|
# Check account move date if exists
|
||||||
if move.account_move_ids:
|
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)
|
# Check valuation layer date (create_date)
|
||||||
svl = self.env['stock.valuation.layer'].search([
|
svl = self.env['stock.valuation.layer'].search([
|
||||||
@ -54,6 +55,5 @@ class TestStockBackdate(TransactionCase):
|
|||||||
], limit=1)
|
], limit=1)
|
||||||
|
|
||||||
if svl:
|
if svl:
|
||||||
# create_date is datetime, backdate is date.
|
# Both are datetime now, so we can compare directly
|
||||||
# We check if the date part matches.
|
self.assertEqual(svl.create_date, backdate, "SVL create_date should be backdated")
|
||||||
self.assertEqual(svl.create_date.date(), backdate, "SVL create_date should be backdated")
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user