Skip to content

Commit

Permalink
[3385][ADD] product_last_purchase_date (#22)
Browse files Browse the repository at this point in the history
[ADD] product_last_purchase_date
  • Loading branch information
AungKoKoLin1997 authored Apr 21, 2023
1 parent 2ca46ab commit 278506c
Show file tree
Hide file tree
Showing 14 changed files with 707 additions and 2 deletions.
56 changes: 56 additions & 0 deletions product_last_purchase_date/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/qrtl/axls-custom/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 <https://github.com/qrtl/axls-custom/issues/new?body=module:%20product_last_purchase_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 Limited

Maintainers
~~~~~~~~~~~

This module is part of the `qrtl/axls-custom <https://github.com/qrtl/axls-custom/tree/16.0/product_last_purchase_date>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions product_last_purchase_date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions product_last_purchase_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
61 changes: 61 additions & 0 deletions product_last_purchase_date/i18n/ja.po
Original file line number Diff line number Diff line change
@@ -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 ""
"過去の納入履歴がないプロダクトにつき、この項目を更新すると最終購入日が設定値で更新されます。"
"設定値より後の日付の納入履歴がある場合は、納入履歴の日付が優先されます。"
2 changes: 2 additions & 0 deletions product_last_purchase_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import product_product
from . import product_template
40 changes: 40 additions & 0 deletions product_last_purchase_date/models/product_product.py
Original file line number Diff line number Diff line change
@@ -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()
55 changes: 55 additions & 0 deletions product_last_purchase_date/models/product_template.py
Original file line number Diff line number Diff line change
@@ -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
)
5 changes: 5 additions & 0 deletions product_last_purchase_date/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading

0 comments on commit 278506c

Please sign in to comment.