-
-
Notifications
You must be signed in to change notification settings - Fork 733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[16.0][ADD] stock_move_actual_date #1711
base: 16.0
Are you sure you want to change the base?
[16.0][ADD] stock_move_actual_date #1711
Conversation
26fa304
to
ebf73d2
Compare
ebf73d2
to
3379d16
Compare
3379d16
to
31121ad
Compare
31121ad
to
cba1f84
Compare
af39fdd
to
69cdb19
Compare
69cdb19
to
86a8263
Compare
# inventory adjustment | ||
force_period_date = self._context.get("force_period_date") | ||
if force_period_date: | ||
self.write({"accounting_date": force_period_date}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AungKoKoLin1997 Never doing a write in a compute !
86a8263
to
825b3d1
Compare
super(TestStockValuation, self).setUp() | ||
|
||
def test_stock_picking_accounting_date(self): | ||
self.product1.categ_id.property_cost_method = "fifo" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.product1.categ_id.property_cost_method = "fifo" |
I guess this assignment doesn't affect the test. Can we ensure that the valuation is real_time
instead?
83171c6
to
2908226
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AungKoKoLin1997 Can you please add another test to ensure that accounting date set in inventory adjustment is not interfered by this module?
1c84542
to
9332b0b
Compare
accounting_date = date.today() + timedelta(days=3) | ||
inventory_quant.accounting_date = accounting_date | ||
inventory_quant.with_context( | ||
skip_exceeded_discrepancy=True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be doing this as this context doesn't belong to a module in the dependency chain. It should ideally be handled by adjusting the stock_inventory_discrepancy
module or by setting rogue modules.
store=True, | ||
) | ||
|
||
@api.depends("date", "accounting_date") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AungKoKoLin1997 Shouldn't it be 'picking_id.accounting_date' ???
def _compute_accounting_date(self): | ||
# 'force_period_date' context is assigned when user sets accounting date in | ||
# inventory adjustment | ||
force_period_date = self._context.get("force_period_date") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like computed stored fields based on context values....
# '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: | ||
for rec in self: | ||
rec.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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the condition based on the context here, as @rousseldenis suggests.
# '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: | |
for rec in self: | |
rec.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) | |
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) |
am_vals = super(StockMove, self)._prepare_account_move_vals( | ||
credit_account_id, | ||
debit_account_id, | ||
journal_id, | ||
qty, | ||
description, | ||
svl_id, | ||
cost, | ||
) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
# 'force_period_date' context is assigned when user sets accounting date in | ||
# inventory adjustment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, missed these lines.
# 'force_period_date' context is assigned when user sets accounting date in | |
# inventory adjustment |
fb02ab9
to
b457c89
Compare
date(2024, 8, 11), | ||
) | ||
|
||
# Test inventory adjustment with actual date |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this into a dedicated test method to make it easier to follow.
) | ||
cls.supplier_location = cls.env.ref("stock.stock_location_suppliers") | ||
cls.stock_location = cls.env.ref("stock.stock_location_stock") | ||
cls.env.user.tz = "Asia/Tokyo" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity of the test scenario, it would be better to put this inside test_stock_move_without_actual_date_from_picking_or_scrap()
which is the only test this setting matters.
adc1c9e
to
1c77025
Compare
_, _ = self.create_picking() | ||
inventory_quant = self.env["stock.quant"].search( | ||
[ | ||
("location_id", "=", self.stock_location.id), | ||
("product_id", "=", self.product_1.id), | ||
] | ||
) | ||
inventory_quant.inventory_quantity = 20.0 | ||
inventory_quant.accounting_date = date(2024, 7, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we just directly create a quant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no reason. Your suggestion is more clear. I updated.
1c77025
to
88ad942
Compare
self.assertEqual( | ||
move.stock_valuation_layer_ids.account_move_id.date, date(2024, 9, 1) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move.stock_valuation_layer_ids
could involve adjustment layers and therefore is not desirable to be relied upon.
self.assertEqual( | |
move.stock_valuation_layer_ids.account_move_id.date, date(2024, 9, 1) | |
) | |
self.assertEqual(move.account_move_ids.date, date(2024, 9, 1)) |
Please apply the same to the rest.
88ad942
to
9f04df4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review.
@AungKoKoLin1997 Please squash commits once it's good to do so.
stock_move_actual_date/hooks.py
Outdated
# Copyright 2024 Quartile (https://www.quartile.co) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openupgradelib import openupgrade |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from openupgradelib import openupgrade | |
from odoo.tools.sql import column_exists |
We don't need openupgradelib?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It is valid.
52b4338
to
b0867ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functional review and Code review.
This PR has the |
b0867ae
to
6fa290b
Compare
@rousseldenis Can you please review this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review. Some minor changes
This module adds actual date in picking and scrap and pass the value to stock move, stock move line and accounting date of SVL's journal entry. When a user makes the transfer for the products with "real time" inventory valuation, effective date in transfer couldn't be selected. And Accounting date for stock valuation journal entry will be the same with effective date. So, for the users who want to specify each transfer's actual accounting date needs to reset to draft manually and change accounting date. This module intends to get rid of this inconvenience by adding actual date in transfer and scrap and then pass to journal entry.
6fa290b
to
44503d6
Compare
This module adds actual date in picking and scrap and pass the value to stock move, stock move line and accounting date of SVL's journal entry.
When a user makes the transfer for the products with "real time" inventory valuation, effective date in transfer couldn't be selected.
And Accounting date for stock valuation journal entry will be the same with effective date.
So, for the users who want to specify each transfer's actual accounting date needs to reset to draft manually and
change accounting date. This module intends to get rid of this inconvenience by adding actual date in transfer and scrap and then pass to journal entry.
@qrtl 4850