Skip to content

Commit

Permalink
[ADD] stock_picking_actual_date
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Sep 23, 2024
1 parent 81e6588 commit 4ec796a
Show file tree
Hide file tree
Showing 26 changed files with 1,103 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_picking_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_picking_actual_date/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
=========================
Stock Picking 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_picking_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_picking_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_picking_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_picking_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_picking_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
19 changes: 19 additions & 0 deletions stock_picking_actual_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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 Picking 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,
}
21 changes: 21 additions & 0 deletions stock_picking_actual_date/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


def pre_init_hook(cr):
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);
"""
)
41 changes: 41 additions & 0 deletions stock_picking_actual_date/i18n/ja.po
Original file line number Diff line number Diff line change
@@ -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 "運送"
7 changes: 7 additions & 0 deletions stock_picking_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_picking_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

Check warning on line 21 in stock_picking_actual_date/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_actual_date/models/account_move.py#L21

Added line #L21 was not covered by tests
self.action_post()
25 changes: 25 additions & 0 deletions stock_picking_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_picking_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)

Check warning on line 12 in stock_picking_actual_date/models/res_currency.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_actual_date/models/res_currency.py#L11-L12

Added lines #L11 - L12 were not covered by tests
75 changes: 75 additions & 0 deletions stock_picking_actual_date/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("actual_date"):
self = self.with_context(actual_date=vals["actual_date"])
return super().create(vals_list)

@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

Check warning on line 64 in stock_picking_actual_date/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_actual_date/models/stock_move.py#L63-L64

Added lines #L63 - L64 were not covered by tests
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()
11 changes: 11 additions & 0 deletions stock_picking_actual_date/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 21 additions & 0 deletions stock_picking_actual_date/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 16 in stock_picking_actual_date/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_actual_date/models/stock_picking.py#L16

Added line #L16 was not covered by tests
account_moves = rec.move_ids.account_move_ids
if not account_moves:
continue

Check warning on line 19 in stock_picking_actual_date/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_actual_date/models/stock_picking.py#L19

Added line #L19 was not covered by tests
account_moves._update_accounting_date()
return res
27 changes: 27 additions & 0 deletions stock_picking_actual_date/models/stock_scrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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 _prepare_move_values(self):
vals = super()._prepare_move_values()
if self.actual_date:
vals["actual_date"] = self.actual_date
return vals

def write(self, vals):
res = super().write(vals)
if "actual_date" in vals:
for rec in self:
if rec.state != "done":
continue

Check warning on line 22 in stock_picking_actual_date/models/stock_scrap.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_actual_date/models/stock_scrap.py#L22

Added line #L22 was not covered by tests
account_moves = rec.move_id.account_move_ids
if not account_moves:
continue

Check warning on line 25 in stock_picking_actual_date/models/stock_scrap.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_actual_date/models/stock_scrap.py#L25

Added line #L25 was not covered by tests
account_moves._update_accounting_date()
return res
Loading

0 comments on commit 4ec796a

Please sign in to comment.