diff --git a/stock_picking_accounting_date/__manifest__.py b/stock_picking_accounting_date/__manifest__.py index 5854e6ab..9a30f3a5 100644 --- a/stock_picking_accounting_date/__manifest__.py +++ b/stock_picking_accounting_date/__manifest__.py @@ -9,6 +9,7 @@ "license": "AGPL-3", "depends": ["stock_account"], "data": [ + "views/stock_move_views.xml", "views/stock_picking_views.xml", ], "installable": True, diff --git a/stock_picking_accounting_date/models/stock_move.py b/stock_picking_accounting_date/models/stock_move.py index fcc9af95..64bced30 100644 --- a/stock_picking_accounting_date/models/stock_move.py +++ b/stock_picking_accounting_date/models/stock_move.py @@ -1,12 +1,24 @@ # Copyright 2023 Quartile Limited # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models +from odoo import api, fields, models class StockMove(models.Model): _inherit = "stock.move" + accounting_date = fields.Date( + compute="_compute_accounting_date", + store=True, + ) + + @api.depends("date", "accounting_date") + def _compute_accounting_date(self): + for line in self: + line.accounting_date = fields.Datetime.context_timestamp(self, line.date) + if line.picking_id.accounting_date: + line.accounting_date = line.picking_id.accounting_date + def _prepare_account_move_vals( self, credit_account_id, @@ -26,6 +38,6 @@ def _prepare_account_move_vals( svl_id, cost, ) - if self.picking_id.accounting_date: - am_vals.update({"date": self.picking_id.accounting_date}) + if self.accounting_date: + am_vals.update({"date": self.accounting_date}) return am_vals diff --git a/stock_picking_accounting_date/models/stock_picking.py b/stock_picking_accounting_date/models/stock_picking.py index ef3ba952..8e0c8e3c 100644 --- a/stock_picking_accounting_date/models/stock_picking.py +++ b/stock_picking_accounting_date/models/stock_picking.py @@ -8,7 +8,6 @@ class StockPicking(models.Model): _inherit = "stock.picking" accounting_date = fields.Date( - states={"done": [("readonly", True)], "cancel": [("readonly", True)]}, help="Accounting date for stock valuation journal entry.", ) show_accounting_date = fields.Boolean(compute="_compute_show_accounting_date") diff --git a/stock_picking_accounting_date/readme/DESCRIPTION.rst b/stock_picking_accounting_date/readme/DESCRIPTION.rst index b2b67119..feddd547 100644 --- a/stock_picking_accounting_date/readme/DESCRIPTION.rst +++ b/stock_picking_accounting_date/readme/DESCRIPTION.rst @@ -1,2 +1,5 @@ -This module adds accounting date in picking and pass the value to accounting date -of SVL's journal entry. +This module adds an accounting date in both stock pickings and stock moves. +The accounting date from the picking is propagated to its corresponding stock move. +If a picking doesn't specify an accounting date, the stock move's accounting date +will be set to the 'Effective Date'. This value is then passed to the SVL's journal entry +accounting date. diff --git a/stock_picking_accounting_date/views/stock_move_views.xml b/stock_picking_accounting_date/views/stock_move_views.xml new file mode 100644 index 00000000..efcda604 --- /dev/null +++ b/stock_picking_accounting_date/views/stock_move_views.xml @@ -0,0 +1,13 @@ + + + + stock.move.tree + stock.move + + + + + + + + diff --git a/stock_picking_accounting_date/views/stock_picking_views.xml b/stock_picking_accounting_date/views/stock_picking_views.xml index cbeaad9d..044900f0 100644 --- a/stock_picking_accounting_date/views/stock_picking_views.xml +++ b/stock_picking_accounting_date/views/stock_picking_views.xml @@ -7,9 +7,14 @@ + diff --git a/stock_valuation_layer_accounting_date/__manifest__.py b/stock_valuation_layer_accounting_date/__manifest__.py index db1d61f6..d1efea80 100644 --- a/stock_valuation_layer_accounting_date/__manifest__.py +++ b/stock_valuation_layer_accounting_date/__manifest__.py @@ -7,7 +7,7 @@ "author": "Quartile Limited, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", "license": "AGPL-3", - "depends": ["stock_account"], + "depends": ["stock_picking_accounting_date"], "data": [ "views/stock_valuation_layer_views.xml", "wizard/stock_quantity_history.xml", diff --git a/stock_valuation_layer_accounting_date/models/stock_valuation_layer.py b/stock_valuation_layer_accounting_date/models/stock_valuation_layer.py index afd59c4a..f65d29bc 100644 --- a/stock_valuation_layer_accounting_date/models/stock_valuation_layer.py +++ b/stock_valuation_layer_accounting_date/models/stock_valuation_layer.py @@ -21,6 +21,9 @@ def _compute_accounting_date(self): if account_move and account_move.state == "posted": rec.accounting_date = account_move.date continue + if rec.stock_move_id: + rec.accounting_date = rec.stock_move_id.accounting_date + continue rec.accounting_date = fields.Datetime.context_timestamp( self, rec.create_date )