Skip to content

Commit

Permalink
[3694][FIX] stock_picking_accounting_date (#22)
Browse files Browse the repository at this point in the history
Before this commit, accounting date set in inventory adjustments would be nullified
as the date of the account move would be overriden by the accounting date field of
the originating stock move, which was missing consideration on the force_period_date
context.

This commit fixes the issue by respecting the context value in assigning the accounting
date in stock moves.
  • Loading branch information
yostashiro authored Feb 14, 2024
1 parent 064e280 commit 530df26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions stock_picking_accounting_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright 2023 Quartile Limited
# Copyright 2023-2024 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Picking Accounting Date",
"version": "16.0.1.0.0",
"version": "16.0.1.0.1",
"author": "Quartile Limited, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Stock",
Expand Down
17 changes: 12 additions & 5 deletions stock_picking_accounting_date/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Quartile Limited
# Copyright 2023-2024 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
Expand All @@ -14,10 +14,17 @@ class StockMove(models.Model):

@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
# 'force_period_date' context is assigned when user sets accounting date in
# inventory adjustment
force_period_date = self._context.get("force_period_date")
if force_period_date:
self.write({"accounting_date": force_period_date})
else:
for rec in self:
if rec.picking_id.accounting_date:
rec.accounting_date = rec.picking_id.accounting_date
continue
rec.accounting_date = fields.Datetime.context_timestamp(self, rec.date)

def _prepare_account_move_vals(
self,
Expand Down

0 comments on commit 530df26

Please sign in to comment.