Skip to content

Commit

Permalink
[3533][ADD] stock_move_ignore_last_purchase_date (#35)
Browse files Browse the repository at this point in the history
* [ADD] stock_move_ignore_purchase_last_date
  • Loading branch information
AungKoKoLin1997 authored Aug 8, 2023
1 parent 2f82921 commit b25864b
Show file tree
Hide file tree
Showing 15 changed files with 634 additions and 3 deletions.
13 changes: 10 additions & 3 deletions product_last_purchase_date/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ 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]
move = self.env["stock.move"].search(
self._get_move_domain(product), order="id desc", limit=1
)
if move:
last_purchase_date = fields.Date.context_today(self, move.date)
if (
Expand All @@ -38,3 +38,10 @@ def _compute_last_purchase_date(self):
last_purchase_date = man_last_purchase_date
product.last_purchase_date = last_purchase_date
product.product_tmpl_id._compute_last_purchase_date()

def _get_move_domain(self, product):
return [
("product_id", "=", product.id),
("state", "=", "done"),
("picking_code", "=", "incoming"),
]
6 changes: 6 additions & 0 deletions setup/stock_move_ignore_last_purchase_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,
)
61 changes: 61 additions & 0 deletions stock_move_ignore_last_purchase_date/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
====================================
Stock Move Ingore 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/stock_move_ignore_last_purchase_date
:alt: qrtl/axls-custom

|badge1| |badge2| |badge3|

This module adds the *Ignore Last Purchase Date* field to the stock move to adjust
assigning to last_purchase_date of product.

Background
~~~~~~~~~~

Certain receipts might be validated later than their actual reception date.
Therefore, the "last purchase date" should not always correspond to the validation date.
In such cases, instead of assigning the validation date to the "last purchase date",
the "man last purchase date" should be used instead.

**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:%20stock_move_ignore_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/stock_move_ignore_last_purchase_date>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions stock_move_ignore_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 stock_move_ignore_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": "Stock Move Ingore Last Purchase Date",
"version": "16.0.1.0.0",
"author": "Quartile Limited",
"website": "https://www.quartile.co",
"category": "Product",
"license": "AGPL-3",
"depends": ["product_last_purchase_date"],
"data": [
"views/stock_picking_views.xml",
"views/stock_move_views.xml",
],
"installable": True,
}
42 changes: 42 additions & 0 deletions stock_move_ignore_last_purchase_date/i18n/ja.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_move_ignore_last_purchase_date
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-12 05:42+0000\n"
"PO-Revision-Date: 2023-07-12 05:42+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_ignore_last_purchase_date
#: model:ir.model.fields,field_description:stock_move_ignore_last_purchase_date.field_stock_move__ignore_last_purchase_date
#: model:ir.model.fields,field_description:stock_move_ignore_last_purchase_date.field_stock_picking__ignore_last_purchase_date
msgid "Ignore Last Purchase Date"
msgstr "最終購入日計算で無視"

#. module: stock_move_ignore_last_purchase_date
#: model:ir.model.fields,help:stock_move_ignore_last_purchase_date.field_stock_move__ignore_last_purchase_date
msgid "Ignore assigning last purchase date"
msgstr "最終購入日計算で無視"

#. module: stock_move_ignore_last_purchase_date
#: model:ir.model,name:stock_move_ignore_last_purchase_date.model_product_product
msgid "Product Variant"
msgstr "プロダクトバリアント"

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

#. module: stock_move_ignore_last_purchase_date
#: model:ir.model,name:stock_move_ignore_last_purchase_date.model_stock_picking
msgid "Transfer"
msgstr "運送"
3 changes: 3 additions & 0 deletions stock_move_ignore_last_purchase_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import stock_move
from . import stock_picking
from . import product_product
14 changes: 14 additions & 0 deletions stock_move_ignore_last_purchase_date/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models
from odoo.osv import expression


class ProductProduct(models.Model):
_inherit = "product.product"

def _get_move_domain(self, product):
domain = super()._get_move_domain(product)
domain = expression.AND([domain, [("ignore_last_purchase_date", "=", False)]])
return domain
20 changes: 20 additions & 0 deletions stock_move_ignore_last_purchase_date/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Quartile Limited
# 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"

ignore_last_purchase_date = fields.Boolean(
compute="_compute_ignore_last_purchase_date",
store=True,
help="Ignore assigning last purchase date",
)

@api.depends("picking_id.ignore_last_purchase_date")
def _compute_ignore_last_purchase_date(self):
for move in self:
move.ignore_last_purchase_date = move.picking_id.ignore_last_purchase_date
move.product_id._compute_last_purchase_date()
10 changes: 10 additions & 0 deletions stock_move_ignore_last_purchase_date/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockPicking(models.Model):
_inherit = "stock.picking"

ignore_last_purchase_date = fields.Boolean()
10 changes: 10 additions & 0 deletions stock_move_ignore_last_purchase_date/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This module adds the *Ignore Last Purchase Date* field to the stock move to adjust
assigning to last_purchase_date of product.

Background
~~~~~~~~~~

Certain receipts might be validated later than their actual reception date.
Therefore, the "last purchase date" should not always correspond to the validation date.
In such cases, instead of assigning the validation date to the "last purchase date",
the "man last purchase date" should be used instead.
Loading

0 comments on commit b25864b

Please sign in to comment.