From d4710b2562cf1b9acad3df7324d402ed452ec9e1 Mon Sep 17 00:00:00 2001 From: "admin.suherdy" Date: Mon, 8 Dec 2025 10:28:06 +0700 Subject: [PATCH] add time field --- __manifest__.py | 4 ++-- models/__pycache__/stock_move.cpython-312.pyc | Bin 3972 -> 4195 bytes .../__pycache__/stock_quant.cpython-312.pyc | Bin 2766 -> 2806 bytes models/stock_move.py | 8 ++++++-- models/stock_quant.py | 12 ++++++------ tests/test_stock_backdate.py | 12 ++++++------ 6 files changed, 20 insertions(+), 16 deletions(-) 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 67217ab0864312b9b6015e690314eda8d0ac8df0..12a09d5c56afde37b4829ae25051622be8ce8ab2 100644 GIT binary patch delta 1068 zcmZWoOH30{6rDGpey2l8r~KN`N-MM=KR*rf5tKiIkr07x2*#4El%&}y>st9y>r*~#Vu`GEGCAY zrAw6s(GLbuMmo=py3#!3b3}cbz{d%&= z)|HCEP$)V*8B<1sv2e<$D4|GDRTV|m(>rcr;vS$U*(%O_38M$cN=G(IQKD776&tHj;j3wL0$={`-Dw-prwbUXeL?&I-G>Z-xnpFQ^;W(GAv>89E}=rQCHR~r zG^xTQ?)`HcJ7@sANTJS$ibu%@cWlGyA^>WH!%< zny48@xn`Qy3`2~czktou#-#umMGfSe{*;8}e*p>GNv*-zj*mj9oI;A92}V?02z~{C z51<$zGmk{A{c)(3o2Zi9GWc~hG^;))PYv^xU+Wt-9Ivk?>jxe-Z9A$Gj;f@iIzDuH zp?}9wvCy$taIgP!o^8R5out|L@~j;y!1ENR&P1}c_-w6Qg<9&(77fLsp=$%tnQ)B~ z!eP1+%J`&0U$l^VvrM{8E~;m`c z51XeDDkbm4mEKH)$ARv!HmX2l8AY;xEmWK>Ilw$U1)B@3nHBCOFDxsx$v&wy-~zfz z02mHKQyAW-EV(rgg(DF~@uRFB@YS?o2YDsAT~@)q>$M4k>~5t+koQV?!L}z-_$iu& z0M+!j)Yjz$KG?TkhUV+h(dkI|4DO^Z@ThJIX$~RuiSZ^F??1$c!v8zddQ=VKv~=j7|Xsz-|OK@qPG(3 z`yRMh^>IdcBbfXaOm4Emu+|N0!{}N!y55B7yWGR3DT4}n_ zY3H3nZn9vHKeU;m7Xzw+9ZH<_9P^cU=M;WYS|goIj; z(1ahfr7N`@-K09&qARhrT6gtZCgYjte`%&B#wZPoVpB1M=wD)4EIplSCc7kodT@FO zq~FpGo=v_`EZVjO^|tAy^*a$<(apGDYTPk{(g?qEQjv_^s3-+@RfauPky7mHw)Otu zDEZN^-}hd6P#T*m7A`x3Y)U?^$xsyl;3t<@=Mvjo+m4t8NR{Pfby3~rsCLNVAM%*D APXGV_ diff --git a/models/__pycache__/stock_quant.cpython-312.pyc b/models/__pycache__/stock_quant.cpython-312.pyc index 179e6b28bb2f2db77df7de94bea5ff90999b1f18..a1745bf3cd70f4e619b801ca5468427ff5cede2b 100644 GIT binary patch delta 146 zcmX>n`c0JgG%qg~0}$}2nPo27$h(n|v3Bx)MsfDUycC6!%-qRW7(+P}U>pr5O*H9r zCWQ3n-ApUlI5=DqOHx5PGdNSUwPu*jx1VW$gJ1On6CRX;E>^0_g7VP%nFyTBsxfr~*#9YxN2vOL#y046vg!T _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")