Skip to content

Commit

Permalink
[4850][ADD] stock_move_actual_date (#160)
Browse files Browse the repository at this point in the history
* [ADD] stock_move_actual_date
  • Loading branch information
kanda999 authored Oct 30, 2024
1 parent e502d04 commit 43f11cc
Show file tree
Hide file tree
Showing 28 changed files with 1,208 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
astor
cryptography
openpyxl
openupgradelib
xlrd
xlsxwriter
6 changes: 6 additions & 0 deletions setup/stock_move_actual_date/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
94 changes: 94 additions & 0 deletions stock_move_actual_date/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/stock-logistics-warehouse/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 <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_move_actual_date%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Quartile

Contributors
~~~~~~~~~~~~

* `Quartile <https://www.quartile.co>`__:

* 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 <https://github.com/OCA/stock-logistics-warehouse/tree/16.0/stock_move_actual_date>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions stock_move_actual_date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import pre_init_hook
20 changes: 20 additions & 0 deletions stock_move_actual_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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"],
"external_dependencies": {"python": ["openupgradelib"]},
"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,
}
24 changes: 24 additions & 0 deletions stock_move_actual_date/hooks.py
Original file line number Diff line number Diff line change
@@ -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);
"""
)
79 changes: 79 additions & 0 deletions stock_move_actual_date/i18n/ja.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_move_actual_date
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-29 09:08+0000\n"
"PO-Revision-Date: 2024-10-29 09:08+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_move_actual_date
#: model:ir.model.fields,field_description:stock_move_actual_date.field_actual_date_mixin__actual_date
#: model:ir.model.fields,field_description:stock_move_actual_date.field_stock_move__actual_date
#: model:ir.model.fields,field_description:stock_move_actual_date.field_stock_move_line__actual_date
#: model:ir.model.fields,field_description:stock_move_actual_date.field_stock_picking__actual_date
#: model:ir.model.fields,field_description:stock_move_actual_date.field_stock_scrap__actual_date
#: model_terms:ir.ui.view,arch_db:stock_move_actual_date.stock_move_line_view_search
#: model_terms:ir.ui.view,arch_db:stock_move_actual_date.stock_scrap_search_view
#: model_terms:ir.ui.view,arch_db:stock_move_actual_date.view_move_search
#: model_terms:ir.ui.view,arch_db:stock_move_actual_date.view_picking_internal_search
msgid "Actual Date"
msgstr "実績日"

#. module: stock_move_actual_date
#: model:ir.model,name:stock_move_actual_date.model_res_currency
msgid "Currency"
msgstr "通貨"

#. module: stock_move_actual_date
#: model:ir.model.fields,help:stock_move_actual_date.field_actual_date_mixin__actual_date
#: model:ir.model.fields,help:stock_move_actual_date.field_stock_picking__actual_date
#: model:ir.model.fields,help:stock_move_actual_date.field_stock_scrap__actual_date
msgid ""
"If set, the value is propagated to the related journal entries as the date."
msgstr ""

#. module: stock_move_actual_date
#: model:ir.model.fields,field_description:stock_move_actual_date.field_actual_date_mixin__is_editable_actual_date
#: model:ir.model.fields,field_description:stock_move_actual_date.field_stock_picking__is_editable_actual_date
#: model:ir.model.fields,field_description:stock_move_actual_date.field_stock_scrap__is_editable_actual_date
msgid "Is Editable"
msgstr ""

#. module: stock_move_actual_date
#: model:ir.model,name:stock_move_actual_date.model_account_move
msgid "Journal Entry"
msgstr "仕訳"

#. module: stock_move_actual_date
#: model:ir.model,name:stock_move_actual_date.model_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr "製品の移動(在庫移動ライン)"

#. module: stock_move_actual_date
#: model:ir.model,name:stock_move_actual_date.model_stock_scrap
msgid "Scrap"
msgstr "廃棄"

#. module: stock_move_actual_date
#: model:ir.model,name:stock_move_actual_date.model_stock_move
msgid "Stock Move"
msgstr "在庫移動"

#. module: stock_move_actual_date
#: model:ir.model,name:stock_move_actual_date.model_stock_picking
msgid "Transfer"
msgstr "在庫転送"

#. module: stock_move_actual_date
#: model:ir.model,name:stock_move_actual_date.model_actual_date_mixin
msgid "actual.date.mixin"
msgstr ""
31 changes: 31 additions & 0 deletions stock_move_actual_date/migrations/16.0.1.0.1/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
# Check if the old column 'accounting_date' exists before attempting to transfer data
if openupgrade.column_exists(env.cr, "stock_picking", "accounting_date"):
env.cr.execute(
"""
UPDATE stock_picking
SET actual_date = accounting_date
WHERE accounting_date IS NOT NULL;
"""
)
env.cr.execute(
"""
UPDATE stock_move
SET actual_date = accounting_date
"""
)
env.cr.execute(
"""
UPDATE stock_move_line sml
SET actual_date = sm.actual_date
FROM stock_move sm
WHERE sml.move_id = sm.id
"""
)
7 changes: 7 additions & 0 deletions stock_move_actual_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions stock_move_actual_date/models/account_move.py
Original file line number Diff line number Diff line change
@@ -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()
25 changes: 25 additions & 0 deletions stock_move_actual_date/models/actual_date_mixin.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions stock_move_actual_date/models/res_currency.py
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit 43f11cc

Please sign in to comment.