diff --git a/product_last_purchase_date/README.rst b/product_last_purchase_date/README.rst new file mode 100644 index 00000000..e9c88b08 --- /dev/null +++ b/product_last_purchase_date/README.rst @@ -0,0 +1,56 @@ +========================== +Product Last Purchase Date +========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-qrtl%2Faxls--custom-lightgray.png?logo=github + :target: https://github.com/qrtl/axls-custom/tree/16.0/product_last_purchase_date + :alt: qrtl/axls-custom + +|badge1| |badge2| |badge3| + +This module adds the *Last Purchase Date* field to the product, for the purpose of rough +aging monitoring of products. + +For products with no past receipt history, the option of updating the date with *Last +Purchase Date (Man.)* is available. + +**Table of contents** + +.. contents:: + :local: + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Quartile Limited + +Maintainers +~~~~~~~~~~~ + +This module is part of the `qrtl/axls-custom `_ project on GitHub. + +You are welcome to contribute. diff --git a/product_last_purchase_date/__init__.py b/product_last_purchase_date/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/product_last_purchase_date/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_last_purchase_date/__manifest__.py b/product_last_purchase_date/__manifest__.py new file mode 100644 index 00000000..d860e192 --- /dev/null +++ b/product_last_purchase_date/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Product Last Purchase Date", + "version": "16.0.1.0.0", + "author": "Quartile Limited", + "website": "https://www.quartile.co", + "category": "Product", + "license": "AGPL-3", + "depends": ["purchase_stock"], + "data": [ + "views/product_product_views.xml", + "views/product_template_views.xml", + ], + "installable": True, +} diff --git a/product_last_purchase_date/i18n/ja.po b/product_last_purchase_date/i18n/ja.po new file mode 100644 index 00000000..55420c20 --- /dev/null +++ b/product_last_purchase_date/i18n/ja.po @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_last_purchase_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-04-20 07:18+0000\n" +"PO-Revision-Date: 2023-04-20 07:18+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: product_last_purchase_date +#: model_terms:ir.ui.view,arch_db:product_last_purchase_date.product_normal_form_view +#: model_terms:ir.ui.view,arch_db:product_last_purchase_date.product_template_only_form_view +msgid "Aging Control" +msgstr "年齢管理" + +#. module: product_last_purchase_date +#: model:ir.model.fields,help:product_last_purchase_date.field_product_product__last_purchase_date +#: model:ir.model.fields,help:product_last_purchase_date.field_product_template__last_purchase_date +msgid "Date of the last receipt from the supplier." +msgstr "仕入先から最後に納入された日" + +#. module: product_last_purchase_date +#: model:ir.model.fields,field_description:product_last_purchase_date.field_product_product__last_purchase_date +#: model:ir.model.fields,field_description:product_last_purchase_date.field_product_template__last_purchase_date +msgid "Last Purchase Date" +msgstr "最終購入日" + +#. module: product_last_purchase_date +#: model:ir.model.fields,field_description:product_last_purchase_date.field_product_product__man_last_purchase_date +#: model:ir.model.fields,field_description:product_last_purchase_date.field_product_template__man_last_purchase_date +msgid "Last Purchase Date (Man.)" +msgstr "最終購入日(手)" + +#. module: product_last_purchase_date +#: model:ir.model,name:product_last_purchase_date.model_product_template +msgid "Product" +msgstr "プロダクト" + +#. module: product_last_purchase_date +#: model:ir.model,name:product_last_purchase_date.model_product_product +msgid "Product Variant" +msgstr "プロダクトバリアント" + +#. module: product_last_purchase_date +#: model:ir.model.fields,help:product_last_purchase_date.field_product_product__man_last_purchase_date +#: model:ir.model.fields,help:product_last_purchase_date.field_product_template__man_last_purchase_date +msgid "" +"Update this field to force set Last Purchase Date in absence of past receipt" +" records. If there is a receipt record dated after this date, the date of the " +"receipt prevails." +msgstr "" +"過去の納入履歴がないプロダクトにつき、この項目を更新すると最終購入日が設定値で更新されます。" +"設定値より後の日付の納入履歴がある場合は、納入履歴の日付が優先されます。" diff --git a/product_last_purchase_date/models/__init__.py b/product_last_purchase_date/models/__init__.py new file mode 100644 index 00000000..18b37e85 --- /dev/null +++ b/product_last_purchase_date/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_product +from . import product_template diff --git a/product_last_purchase_date/models/product_product.py b/product_last_purchase_date/models/product_product.py new file mode 100644 index 00000000..1377e8db --- /dev/null +++ b/product_last_purchase_date/models/product_product.py @@ -0,0 +1,40 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class Product(models.Model): + _inherit = "product.product" + + man_last_purchase_date = fields.Date( + "Last Purchase Date (Man.)", + copy=False, + help="Update this field to force set Last Purchase Date in absence of past " + "receipt records. If there is a receipt record dated after this date, the date " + "of the receipt prevails.", + ) + last_purchase_date = fields.Date( + compute="_compute_last_purchase_date", + store=True, + help="Date of the last receipt from the supplier.", + ) + + @api.depends("stock_move_ids.state", "man_last_purchase_date") + def _compute_last_purchase_date(self): + for product in self: + last_purchase_date = False + man_last_purchase_date = product.man_last_purchase_date + move = product.stock_move_ids.filtered( + lambda m: m.state == "done" and m.picking_code == "incoming" + ).sorted(key=lambda m: m.id, reverse=True)[:1] + if move: + last_purchase_date = fields.Date.context_today(self, move.date) + if ( + not last_purchase_date + or man_last_purchase_date + and man_last_purchase_date > last_purchase_date + ): + last_purchase_date = man_last_purchase_date + product.last_purchase_date = last_purchase_date + product.product_tmpl_id._compute_last_purchase_date() diff --git a/product_last_purchase_date/models/product_template.py b/product_last_purchase_date/models/product_template.py new file mode 100644 index 00000000..8ef0faf0 --- /dev/null +++ b/product_last_purchase_date/models/product_template.py @@ -0,0 +1,55 @@ +# Copyright 2023 Quartile Limited +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + man_last_purchase_date = fields.Date( + "Last Purchase Date (Man.)", + compute="_compute_last_purchase_date", + inverse="_inverse_man_last_purchase_date", + store=True, + copy=False, + help="Update this field to force set Last Purchase Date in absence of past " + "receipt records. If there is a receipt record dated after this date, the date " + "of the receipt prevails.", + ) + last_purchase_date = fields.Date( + compute="_compute_last_purchase_date", + store=True, + help="Date of the last receipt from the supplier.", + ) + + @api.depends( + "product_variant_ids", + "product_variant_ids.man_last_purchase_date", + "product_variant_ids.last_purchase_date", + ) + def _compute_last_purchase_date(self): + unique_variants = self.filtered( + lambda template: len(template.product_variant_ids) == 1 + ) + for template in unique_variants: + template.man_last_purchase_date = ( + template.product_variant_ids.man_last_purchase_date + ) + last_purchase_date = template.product_variant_ids.last_purchase_date + man_last_purchase_date = template.man_last_purchase_date + if man_last_purchase_date and man_last_purchase_date > last_purchase_date: + last_purchase_date = man_last_purchase_date + template.last_purchase_date = last_purchase_date + for template in self - unique_variants: + template.man_last_purchase_date = False + template.last_purchase_date = False + + # This method is triggered upon save, therefore the UX of last_purchase_date update + # of product.template is not as instant as that of product.product. + def _inverse_man_last_purchase_date(self): + for template in self: + if len(template.product_variant_ids) == 1: + template.product_variant_ids.man_last_purchase_date = ( + template.man_last_purchase_date + ) diff --git a/product_last_purchase_date/readme/DESCRIPTION.rst b/product_last_purchase_date/readme/DESCRIPTION.rst new file mode 100644 index 00000000..c408ab80 --- /dev/null +++ b/product_last_purchase_date/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module adds the *Last Purchase Date* field to the product, for the purpose of rough +aging monitoring of products. + +For products with no past receipt history, the option of updating the date with *Last +Purchase Date (Man.)* is available. diff --git a/product_last_purchase_date/static/description/index.html b/product_last_purchase_date/static/description/index.html new file mode 100644 index 00000000..b0ce7389 --- /dev/null +++ b/product_last_purchase_date/static/description/index.html @@ -0,0 +1,410 @@ + + + + + + +Product Last Purchase Date + + + +
+

Product Last Purchase Date

+ + +

Beta License: AGPL-3 qrtl/axls-custom

+

This module adds the Last Purchase Date field to the product, for the purpose of rough +aging monitoring of products.

+

For products with no past receipt history, the option of updating the date with Last +Purchase Date (Man.) is available.

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Quartile Limited
  • +
+
+
+

Maintainers

+

This module is part of the qrtl/axls-custom project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/product_last_purchase_date/views/product_product_views.xml b/product_last_purchase_date/views/product_product_views.xml new file mode 100644 index 00000000..10cb4b4e --- /dev/null +++ b/product_last_purchase_date/views/product_product_views.xml @@ -0,0 +1,26 @@ + + + + product.product.tree + product.product + + + + + + + + + product.product.form + product.product + + + + + + + + + + + diff --git a/product_last_purchase_date/views/product_template_views.xml b/product_last_purchase_date/views/product_template_views.xml new file mode 100644 index 00000000..7f561ae3 --- /dev/null +++ b/product_last_purchase_date/views/product_template_views.xml @@ -0,0 +1,26 @@ + + + + product.template.product.tree + product.template + + + + + + + + + product.template.product.form + product.template + + + + + + + + + + + diff --git a/setup/product_last_purchase_date/odoo/addons/product_last_purchase_date b/setup/product_last_purchase_date/odoo/addons/product_last_purchase_date new file mode 120000 index 00000000..2194c3ec --- /dev/null +++ b/setup/product_last_purchase_date/odoo/addons/product_last_purchase_date @@ -0,0 +1 @@ +../../../../product_last_purchase_date \ No newline at end of file diff --git a/setup/product_last_purchase_date/setup.py b/setup/product_last_purchase_date/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/product_last_purchase_date/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_product_shelfinfo/views/product_template_views.xml b/stock_product_shelfinfo/views/product_template_views.xml index d11220dc..d73e15e6 100644 --- a/stock_product_shelfinfo/views/product_template_views.xml +++ b/stock_product_shelfinfo/views/product_template_views.xml @@ -6,11 +6,11 @@ - +