From c0466486511938d80be3e318cea7f02f9257fa1d Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Tue, 27 Dec 2022 10:42:41 +0630 Subject: [PATCH] [ADD] stock_move_actual_date --- .../odoo/addons/stock_move_actual_date | 1 + setup/stock_move_actual_date/setup.py | 6 + stock_move_actual_date/README.rst | 94 ++++ stock_move_actual_date/__init__.py | 2 + stock_move_actual_date/__manifest__.py | 19 + stock_move_actual_date/hooks.py | 24 + stock_move_actual_date/i18n/ja.po | 41 ++ stock_move_actual_date/models/__init__.py | 7 + stock_move_actual_date/models/account_move.py | 22 + .../models/actual_date_mixin.py | 25 + stock_move_actual_date/models/res_currency.py | 12 + stock_move_actual_date/models/stock_move.py | 68 +++ .../models/stock_move_line.py | 11 + .../models/stock_picking.py | 21 + stock_move_actual_date/models/stock_scrap.py | 30 ++ .../readme/CONTRIBUTORS.rst | 4 + stock_move_actual_date/readme/DESCRIPTION.rst | 1 + stock_move_actual_date/readme/ROADMAP.rst | 3 + stock_move_actual_date/readme/USAGE.rst | 4 + .../static/description/index.html | 439 ++++++++++++++++++ stock_move_actual_date/tests/__init__.py | 1 + .../tests/test_stock_move_actual_date.py | 146 ++++++ .../views/stock_move_line_views.xml | 35 ++ .../views/stock_move_views.xml | 35 ++ .../views/stock_picking_views.xml | 50 ++ .../views/stock_scrap_views.xml | 59 +++ 26 files changed, 1160 insertions(+) create mode 120000 setup/stock_move_actual_date/odoo/addons/stock_move_actual_date create mode 100644 setup/stock_move_actual_date/setup.py create mode 100644 stock_move_actual_date/README.rst create mode 100644 stock_move_actual_date/__init__.py create mode 100644 stock_move_actual_date/__manifest__.py create mode 100644 stock_move_actual_date/hooks.py create mode 100644 stock_move_actual_date/i18n/ja.po create mode 100644 stock_move_actual_date/models/__init__.py create mode 100644 stock_move_actual_date/models/account_move.py create mode 100644 stock_move_actual_date/models/actual_date_mixin.py create mode 100644 stock_move_actual_date/models/res_currency.py create mode 100644 stock_move_actual_date/models/stock_move.py create mode 100644 stock_move_actual_date/models/stock_move_line.py create mode 100644 stock_move_actual_date/models/stock_picking.py create mode 100644 stock_move_actual_date/models/stock_scrap.py create mode 100644 stock_move_actual_date/readme/CONTRIBUTORS.rst create mode 100644 stock_move_actual_date/readme/DESCRIPTION.rst create mode 100644 stock_move_actual_date/readme/ROADMAP.rst create mode 100644 stock_move_actual_date/readme/USAGE.rst create mode 100644 stock_move_actual_date/static/description/index.html create mode 100644 stock_move_actual_date/tests/__init__.py create mode 100644 stock_move_actual_date/tests/test_stock_move_actual_date.py create mode 100644 stock_move_actual_date/views/stock_move_line_views.xml create mode 100644 stock_move_actual_date/views/stock_move_views.xml create mode 100644 stock_move_actual_date/views/stock_picking_views.xml create mode 100644 stock_move_actual_date/views/stock_scrap_views.xml diff --git a/setup/stock_move_actual_date/odoo/addons/stock_move_actual_date b/setup/stock_move_actual_date/odoo/addons/stock_move_actual_date new file mode 120000 index 000000000000..d64065ff311a --- /dev/null +++ b/setup/stock_move_actual_date/odoo/addons/stock_move_actual_date @@ -0,0 +1 @@ +../../../../stock_move_actual_date \ No newline at end of file diff --git a/setup/stock_move_actual_date/setup.py b/setup/stock_move_actual_date/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/stock_move_actual_date/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_move_actual_date/README.rst b/stock_move_actual_date/README.rst new file mode 100644 index 000000000000..35cf4f7845ab --- /dev/null +++ b/stock_move_actual_date/README.rst @@ -0,0 +1,94 @@ +====================== +Stock Move Actual Date +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d70c1f46222bd6a5f01ae300908138b08df6c418a5dc4eb01168cd345ba95e59 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/16.0/stock_move_actual_date + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-16-0/stock-logistics-warehouse-16-0-stock_move_actual_date + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds an Actual Date field to the stock picking, stock scrap, stock move, and stock move line models. This field allows users to record the actual date on which a stock transfer or stock scrap took place, in case the transaction in Odoo is processed after the fact. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Use this module's function in the following situations: + +* If you are late in processing a transfer or scrap in Odoo and wish to record the transaction with the actual transfer date, fill in the Actual Date field in the picking or scrap form. The Actual Date of the picking or scrap is then propagated to its corresponding stock moves and stock move lines, and is also passed to the journal entry as the date. +* You can also update the Actual Date of a completed picking or scrap if you belong to the Inventory Manager group. This operation updates the date of the related journal entries, re-proposing a new sequence to them as necessary. + +Known issues / Roadmap +====================== + +Updating the Actual Date of a completed receipt picking for a foreign currency purchase does not trigger a recalculation of the amounts in the associated journal entries, even if the currency rate for the new date differs. + +For the Actual Date of existing stock move and stock move line records created before this module was installed, the user's timezone will not be considered, and only the date part from the 'date' field in the UTC timezone will be assigned. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Quartile + +Contributors +~~~~~~~~~~~~ + +* `Quartile `__: + + * Aung Ko Ko Lin + * Yoshi Tashiro + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_move_actual_date/__init__.py b/stock_move_actual_date/__init__.py new file mode 100644 index 000000000000..6d58305f5ddc --- /dev/null +++ b/stock_move_actual_date/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import pre_init_hook diff --git a/stock_move_actual_date/__manifest__.py b/stock_move_actual_date/__manifest__.py new file mode 100644 index 000000000000..97919aaea15c --- /dev/null +++ b/stock_move_actual_date/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Stock Move Actual Date", + "version": "16.0.1.0.0", + "author": "Quartile, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "category": "Stock", + "license": "AGPL-3", + "depends": ["stock_account"], + "data": [ + "views/stock_move_line_views.xml", + "views/stock_move_views.xml", + "views/stock_picking_views.xml", + "views/stock_scrap_views.xml", + ], + "pre_init_hook": "pre_init_hook", + "installable": True, +} diff --git a/stock_move_actual_date/hooks.py b/stock_move_actual_date/hooks.py new file mode 100644 index 000000000000..e34da17d0205 --- /dev/null +++ b/stock_move_actual_date/hooks.py @@ -0,0 +1,24 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +def pre_init_hook(cr): + if not openupgrade.column_exists(cr, "stock_move", "actual_date"): + cr.execute( + """ + ALTER TABLE stock_move + ADD COLUMN actual_date DATE; + UPDATE stock_move + SET actual_date = DATE(date); + """ + ) + cr.execute( + """ + ALTER TABLE stock_move_line + ADD COLUMN actual_date DATE; + UPDATE stock_move_line + SET actual_date = DATE(date); + """ + ) diff --git a/stock_move_actual_date/i18n/ja.po b/stock_move_actual_date/i18n/ja.po new file mode 100644 index 000000000000..ad7120bfca67 --- /dev/null +++ b/stock_move_actual_date/i18n/ja.po @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_accounting_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-05-18 04:34+0000\n" +"PO-Revision-Date: 2023-05-18 04:34+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_picking_accounting_date +#: model:ir.model.fields,field_description:stock_picking_accounting_date.field_stock_picking__accounting_date +msgid "Accounting Date" +msgstr "会計日" + +#. module: stock_picking_accounting_date +#: model:ir.model.fields,help:stock_picking_accounting_date.field_stock_picking__accounting_date +msgid "Accounting date for stock valuation journal entry." +msgstr "在庫評価仕訳の会計日" + +#. module: stock_picking_accounting_date +#: model:ir.model.fields,field_description:stock_picking_accounting_date.field_stock_picking__show_accounting_date +msgid "Show Accounting Date" +msgstr "会計日を表示" + +#. module: stock_picking_accounting_date +#: model:ir.model,name:stock_picking_accounting_date.model_stock_move +msgid "Stock Move" +msgstr "在庫移動" + +#. module: stock_picking_accounting_date +#: model:ir.model,name:stock_picking_accounting_date.model_stock_picking +msgid "Transfer" +msgstr "運送" diff --git a/stock_move_actual_date/models/__init__.py b/stock_move_actual_date/models/__init__.py new file mode 100644 index 000000000000..eeae0b877c33 --- /dev/null +++ b/stock_move_actual_date/models/__init__.py @@ -0,0 +1,7 @@ +from . import account_move +from . import actual_date_mixin +from . import res_currency +from . import stock_move +from . import stock_move_line +from . import stock_picking +from . import stock_scrap diff --git a/stock_move_actual_date/models/account_move.py b/stock_move_actual_date/models/account_move.py new file mode 100644 index 000000000000..859ea3e44a91 --- /dev/null +++ b/stock_move_actual_date/models/account_move.py @@ -0,0 +1,22 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountMove(models.Model): + _inherit = "account.move" + + def _must_check_constrains_date_sequence(self): + if self.env.context.get("skip_date_sequence_check"): + return False + return super()._must_check_constrains_date_sequence() + + def _update_accounting_date(self): + self.button_draft() + for move in self: + move = move.with_context(skip_date_sequence_check=True) + move.date = move.stock_move_id.actual_date + if not move._sequence_matches_date(): + move.name = False + self.action_post() diff --git a/stock_move_actual_date/models/actual_date_mixin.py b/stock_move_actual_date/models/actual_date_mixin.py new file mode 100644 index 000000000000..e302fc31017d --- /dev/null +++ b/stock_move_actual_date/models/actual_date_mixin.py @@ -0,0 +1,25 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ActualDateMixin(models.AbstractModel): + _name = "actual.date.mixin" + + actual_date = fields.Date( + tracking=True, + help="If set, the value is propagated " + "to the related journal entries as the date.", + ) + is_editable_actual_date = fields.Boolean( + compute="_compute_is_editable_actual_date", string="Is Editable" + ) + + def _compute_is_editable_actual_date(self): + for rec in self: + rec.is_editable_actual_date = False + if rec.state not in ["done", "cancel"] or self.env.user.has_group( + "stock.group_stock_manager" + ): + rec.is_editable_actual_date = True diff --git a/stock_move_actual_date/models/res_currency.py b/stock_move_actual_date/models/res_currency.py new file mode 100644 index 000000000000..f83c16693a40 --- /dev/null +++ b/stock_move_actual_date/models/res_currency.py @@ -0,0 +1,12 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ResCurrency(models.Model): + _inherit = "res.currency" + + def _convert(self, from_amount, to_currency, company, date, round=True): + date = self.env.context.get("actual_date") or date + return super()._convert(from_amount, to_currency, company, date, round) diff --git a/stock_move_actual_date/models/stock_move.py b/stock_move_actual_date/models/stock_move.py new file mode 100644 index 000000000000..b8f76a82786f --- /dev/null +++ b/stock_move_actual_date/models/stock_move.py @@ -0,0 +1,68 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + actual_date = fields.Date( + compute="_compute_actual_date", + store=True, + ) + + def _get_timezone(self): + return self.env.context.get("tz") or self.env.user.tz or "UTC" + + @api.depends("date", "picking_id.actual_date", "scrap_ids.actual_date") + def _compute_actual_date(self): + tz = self._get_timezone() + for rec in self: + actual_date = ( + self.env.context.get("actual_date") or rec.scrap_ids.actual_date + ) + if actual_date: + rec.actual_date = actual_date + continue + if not rec.scrapped and rec.picking_id.actual_date: + rec.actual_date = rec.picking_id.actual_date + continue + rec.actual_date = fields.Date.context_today( + self.with_context(tz=tz), rec.date + ) + + def _prepare_account_move_vals( + self, + credit_account_id, + debit_account_id, + journal_id, + qty, + description, + svl_id, + cost, + ): + am_vals = super(StockMove, self)._prepare_account_move_vals( + credit_account_id, + debit_account_id, + journal_id, + qty, + description, + svl_id, + cost, + ) + # i.e. Inventory adjustments with actual date + if self._context.get("force_period_date"): + self.write({"actual_date": self._context["force_period_date"]}) + return am_vals + if self.actual_date: + am_vals.update({"date": self.actual_date}) + return am_vals + + def _get_price_unit(self): + """Passes the actual_date to be used in currency conversion for receipts + in foreign currency purchases. + """ + self.ensure_one() + self = self.with_context(actual_date=self.actual_date) + return super()._get_price_unit() diff --git a/stock_move_actual_date/models/stock_move_line.py b/stock_move_actual_date/models/stock_move_line.py new file mode 100644 index 000000000000..5ac644f21a20 --- /dev/null +++ b/stock_move_actual_date/models/stock_move_line.py @@ -0,0 +1,11 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import fields, models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + actual_date = fields.Date(related="move_id.actual_date", store=True) diff --git a/stock_move_actual_date/models/stock_picking.py b/stock_move_actual_date/models/stock_picking.py new file mode 100644 index 000000000000..b49c6673c1d0 --- /dev/null +++ b/stock_move_actual_date/models/stock_picking.py @@ -0,0 +1,21 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockPicking(models.Model): + _name = "stock.picking" + _inherit = ["stock.picking", "actual.date.mixin"] + + def write(self, vals): + res = super().write(vals) + if "actual_date" in vals: + for rec in self: + if rec.state != "done": + continue + account_moves = rec.move_ids.account_move_ids + if not account_moves: + continue + account_moves._update_accounting_date() + return res diff --git a/stock_move_actual_date/models/stock_scrap.py b/stock_move_actual_date/models/stock_scrap.py new file mode 100644 index 000000000000..7dd42ab21eb6 --- /dev/null +++ b/stock_move_actual_date/models/stock_scrap.py @@ -0,0 +1,30 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockScrap(models.Model): + _name = "stock.scrap" + _inherit = ["stock.scrap", "actual.date.mixin"] + + def write(self, vals): + res = super().write(vals) + if "actual_date" in vals: + for rec in self: + if rec.state != "done": + continue + account_moves = rec.move_id.account_move_ids + if not account_moves: + continue + account_moves._update_accounting_date() + return res + + def do_scrap(self): + """Passes the actual_date as context to be used in _compute_actual_date() + of stock move. + """ + for scrap in self: + scrap = scrap.with_context(actual_date=scrap.actual_date) + super(StockScrap, scrap).do_scrap() + return True diff --git a/stock_move_actual_date/readme/CONTRIBUTORS.rst b/stock_move_actual_date/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..5c1d25fa2798 --- /dev/null +++ b/stock_move_actual_date/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Quartile `__: + + * Aung Ko Ko Lin + * Yoshi Tashiro diff --git a/stock_move_actual_date/readme/DESCRIPTION.rst b/stock_move_actual_date/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..cd4d26d8dc8b --- /dev/null +++ b/stock_move_actual_date/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds an Actual Date field to the stock picking, stock scrap, stock move, and stock move line models. This field allows users to record the actual date on which a stock transfer or stock scrap took place, in case the transaction in Odoo is processed after the fact. diff --git a/stock_move_actual_date/readme/ROADMAP.rst b/stock_move_actual_date/readme/ROADMAP.rst new file mode 100644 index 000000000000..15882d888d38 --- /dev/null +++ b/stock_move_actual_date/readme/ROADMAP.rst @@ -0,0 +1,3 @@ +Updating the Actual Date of a completed receipt picking for a foreign currency purchase does not trigger a recalculation of the amounts in the associated journal entries, even if the currency rate for the new date differs. + +For the Actual Date of existing stock move and stock move line records created before this module was installed, the user's timezone will not be considered, and only the date part from the 'date' field in the UTC timezone will be assigned. diff --git a/stock_move_actual_date/readme/USAGE.rst b/stock_move_actual_date/readme/USAGE.rst new file mode 100644 index 000000000000..9b368eef4e17 --- /dev/null +++ b/stock_move_actual_date/readme/USAGE.rst @@ -0,0 +1,4 @@ +Use this module's function in the following situations: + +* If you are late in processing a transfer or scrap in Odoo and wish to record the transaction with the actual transfer date, fill in the Actual Date field in the picking or scrap form. The Actual Date of the picking or scrap is then propagated to its corresponding stock moves and stock move lines, and is also passed to the journal entry as the date. +* You can also update the Actual Date of a completed picking or scrap if you belong to the Inventory Manager group. This operation updates the date of the related journal entries, re-proposing a new sequence to them as necessary. diff --git a/stock_move_actual_date/static/description/index.html b/stock_move_actual_date/static/description/index.html new file mode 100644 index 000000000000..a2b394fef985 --- /dev/null +++ b/stock_move_actual_date/static/description/index.html @@ -0,0 +1,439 @@ + + + + + +Stock Move Actual Date + + + +
+

Stock Move Actual Date

+ + +

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runboat

+

This module adds an Actual Date field to the stock picking, stock scrap, stock move, and stock move line models. This field allows users to record the actual date on which a stock transfer or stock scrap took place, in case the transaction in Odoo is processed after the fact.

+

Table of contents

+ +
+

Usage

+

Use this module’s function in the following situations:

+
    +
  • If you are late in processing a transfer or scrap in Odoo and wish to record the transaction with the actual transfer date, fill in the Actual Date field in the picking or scrap form. The Actual Date of the picking or scrap is then propagated to its corresponding stock moves and stock move lines, and is also passed to the journal entry as the date.
  • +
  • You can also update the Actual Date of a completed picking or scrap if you belong to the Inventory Manager group. This operation updates the date of the related journal entries, re-proposing a new sequence to them as necessary.
  • +
+
+
+

Known issues / Roadmap

+

Updating the Actual Date of a completed receipt picking for a foreign currency purchase does not trigger a recalculation of the amounts in the associated journal entries, even if the currency rate for the new date differs.

+

For the Actual Date of existing stock move and stock move line records created before this module was installed, the user’s timezone will not be considered, and only the date part from the ‘date’ field in the UTC timezone will be assigned.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Quartile
  • +
+
+
+

Contributors

+
    +
  • Quartile:
      +
    • Aung Ko Ko Lin
    • +
    • Yoshi Tashiro
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/stock-logistics-warehouse project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_move_actual_date/tests/__init__.py b/stock_move_actual_date/tests/__init__.py new file mode 100644 index 000000000000..e081a2fdbf1b --- /dev/null +++ b/stock_move_actual_date/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_move_actual_date diff --git a/stock_move_actual_date/tests/test_stock_move_actual_date.py b/stock_move_actual_date/tests/test_stock_move_actual_date.py new file mode 100644 index 000000000000..20893eca22f1 --- /dev/null +++ b/stock_move_actual_date/tests/test_stock_move_actual_date.py @@ -0,0 +1,146 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import date + +from freezegun import freeze_time + +from odoo.tests.common import TransactionCase + + +class TestStockMoveActualDate(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create({"name": "Test Partner"}) + product_category = cls.env["product.category"].create( + { + "name": "Test Category", + "property_cost_method": "fifo", + "property_valuation": "real_time", + } + ) + cls.product_1 = cls.env["product.product"].create( + { + "name": "Test Product", + "type": "product", + "categ_id": product_category.id, + } + ) + 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" + + def create_picking(self, actual_date=False): + receipt = self.env["stock.picking"].create( + { + "location_id": self.supplier_location.id, + "location_dest_id": self.stock_location.id, + "partner_id": self.partner.id, + "picking_type_id": self.env.ref("stock.picking_type_in").id, + "actual_date": actual_date, + } + ) + + move = self.env["stock.move"].create( + { + "picking_id": receipt.id, + "name": "10 in", + "location_id": self.supplier_location.id, + "location_dest_id": self.stock_location.id, + "product_id": self.product_1.id, + "product_uom_qty": 10.0, + "price_unit": 10, + "move_line_ids": [ + ( + 0, + 0, + { + "product_id": self.product_1.id, + "location_id": self.supplier_location.id, + "location_dest_id": self.stock_location.id, + "qty_done": 10.0, + }, + ) + ], + } + ) + move._action_confirm() + move._action_done() + return receipt, move + + def create_scrap(self, receipt, actual_date=False): + scrap = self.env["stock.scrap"].create( + { + "product_id": self.product_1.id, + "scrap_qty": 2.0, + "picking_id": receipt.id, + "actual_date": actual_date, + } + ) + scrap.action_validate() + return scrap + + def test_stock_move_actual_date(self): + actual_date = date(2024, 9, 1) + receipt, move = self.create_picking(actual_date) + self.assertEqual(move.actual_date, actual_date) + self.assertEqual( + move.stock_valuation_layer_ids.account_move_id.date, actual_date + ) + # Update actual_date after done + new_actual_date = date(2024, 8, 1) + receipt.actual_date = new_actual_date + self.assertEqual(move.actual_date, new_actual_date) + self.assertEqual( + move.stock_valuation_layer_ids.account_move_id.date, new_actual_date + ) + actual_date = date(2024, 9, 10) + # Create scrap + scrap = self.create_scrap(receipt, actual_date) + self.assertEqual(scrap.move_id.actual_date, actual_date) + self.assertEqual( + scrap.move_id.stock_valuation_layer_ids.account_move_id.date, actual_date + ) + # Update actual_date after done + new_actual_date = date(2024, 8, 11) + scrap.actual_date = new_actual_date + self.assertEqual(scrap.move_id.actual_date, new_actual_date) + self.assertEqual( + scrap.move_id.stock_valuation_layer_ids.account_move_id.date, + new_actual_date, + ) + + # Test inventory adjustment with actual date + inventory_quant = self.env["stock.quant"].search( + [ + ("location_id", "=", self.stock_location.id), + ("product_id", "=", self.product_1.id), + ] + ) + actual_date = date(2024, 7, 1) + inventory_quant.inventory_quantity = 20.0 + inventory_quant.accounting_date = actual_date + inventory_quant.action_apply_inventory() + move = self.env["stock.move"].search( + [("product_id", "=", self.product_1.id), ("is_inventory", "=", True)], + limit=1, + ) + self.assertEqual(move.actual_date, actual_date) + self.assertEqual( + move.stock_valuation_layer_ids.account_move_id.date, actual_date + ) + + @freeze_time("2024-09-20 23:00:00") + def test_stock_move_without_actual_date_from_picking_or_scrap(self): + receipt, move = self.create_picking() + self.assertEqual(move.actual_date, date(2024, 9, 21)) + self.assertEqual( + move.stock_valuation_layer_ids.account_move_id.date, date(2024, 9, 21) + ) + scrap = self.create_scrap(receipt) + self.assertEqual(scrap.move_id.actual_date, date(2024, 9, 21)) + self.assertEqual( + scrap.move_id.stock_valuation_layer_ids.account_move_id.date, + date(2024, 9, 21), + ) diff --git a/stock_move_actual_date/views/stock_move_line_views.xml b/stock_move_actual_date/views/stock_move_line_views.xml new file mode 100644 index 000000000000..e14b4009bbc9 --- /dev/null +++ b/stock_move_actual_date/views/stock_move_line_views.xml @@ -0,0 +1,35 @@ + + + + stock.move.line.search + stock.move.line + + + + + + + + + + + + stock.move.line.tree + stock.move.line + + + + + + + + diff --git a/stock_move_actual_date/views/stock_move_views.xml b/stock_move_actual_date/views/stock_move_views.xml new file mode 100644 index 000000000000..2e2d7aa2c1d3 --- /dev/null +++ b/stock_move_actual_date/views/stock_move_views.xml @@ -0,0 +1,35 @@ + + + + stock.move.search + stock.move + + + + + + + + + + + + stock.move.tree + stock.move + + + + + + + + diff --git a/stock_move_actual_date/views/stock_picking_views.xml b/stock_move_actual_date/views/stock_picking_views.xml new file mode 100644 index 000000000000..867c84781acf --- /dev/null +++ b/stock_move_actual_date/views/stock_picking_views.xml @@ -0,0 +1,50 @@ + + + + stock.picking.search + stock.picking + + + + + + + + + + + + + stock.picking.form + stock.picking + + + + + + + + + + stock.picking.tree + stock.picking + + + + + + + + diff --git a/stock_move_actual_date/views/stock_scrap_views.xml b/stock_move_actual_date/views/stock_scrap_views.xml new file mode 100644 index 000000000000..5d91b3f9c14d --- /dev/null +++ b/stock_move_actual_date/views/stock_scrap_views.xml @@ -0,0 +1,59 @@ + + + + stock.scrap.search + stock.scrap + + + + + + + + + + + + stock.scrap.tree + stock.scrap + + + + + + + + + stock.scrap.form + stock.scrap + + + + + + + + + + stock.scrap.view.form2.inherit.mrp + stock.scrap + + + + + + + +