Skip to content

Commit

Permalink
[16.0][ADD] stock_production_lot_expired_date
Browse files Browse the repository at this point in the history
  • Loading branch information
glitchov committed Jan 24, 2023
1 parent c7f6249 commit 0071730
Show file tree
Hide file tree
Showing 15 changed files with 513 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_production_lot_expired_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,
)
84 changes: 84 additions & 0 deletions stock_production_lot_expired_date/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
=================================
Stock production lot expired 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-OCA%2Fproduct--attribute-lightgray.png?logo=github
:target: https://github.com/OCA/product-attribute/tree/16.0/stock_production_lot_expired_date
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-stock_production_lot_expired_date
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/product-attribute&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to facilitate the input of stock production lot expired dates:

* Add settings on stock to choose the base date for stock production lot
* Add onchanges on stock production lot to compute expired dates from base date

**Table of contents**

.. contents::
:local:

Usage
=====

# Go to *Settings > Inventory > Traceability*
There you can set the base date under *Base date to compute expiration dates*

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/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/OCA/product-attribute/issues/new?body=module:%20stock_production_lot_expired_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
~~~~~~~

* Camptocamp
* ACSONE SA/NV

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

* Julien Coux <[email protected]>
* Hughes Damry <[email protected]>

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/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/stock_production_lot_expired_date>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions stock_production_lot_expired_date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions stock_production_lot_expired_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2016 Julien Coux (Camptocamp)
# Copyright 2022 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Stock production lot expired date",
"version": "16.0.1.0.0",
"author": "Camptocamp, ACSONE SA/NV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Product",
"depends": ["product_expiry", "stock"],
"website": "https://github.com/OCA/product-attribute",
"data": ["views/res_config_settings.xml"],
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_production_lot_expired_date
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-30 11:04+0000\n"
"PO-Revision-Date: 2022-11-30 11:04+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_production_lot_expired_date
#. odoo-python
#: code:addons/stock_production_lot_expired_date/models/res_config_settings.py:0
#, python-format
msgid "Alert date"
msgstr ""

#. module: stock_production_lot_expired_date
#: model:ir.model.fields,field_description:stock_production_lot_expired_date.field_res_config_settings__production_lot_base_date
msgid "Base date to compute expiration dates"
msgstr ""

#. module: stock_production_lot_expired_date
#: model:ir.model,name:stock_production_lot_expired_date.model_res_config_settings
msgid "Config Settings"
msgstr ""

#. module: stock_production_lot_expired_date
#. odoo-python
#: code:addons/stock_production_lot_expired_date/models/res_config_settings.py:0
#, python-format
msgid "Expiration date"
msgstr ""

#. module: stock_production_lot_expired_date
#: model:ir.model,name:stock_production_lot_expired_date.model_stock_lot
msgid "Lot/Serial"
msgstr ""

#. module: stock_production_lot_expired_date
#. odoo-python
#: code:addons/stock_production_lot_expired_date/models/res_config_settings.py:0
#, python-format
msgid "Removal date"
msgstr ""

#. module: stock_production_lot_expired_date
#. odoo-python
#: code:addons/stock_production_lot_expired_date/models/res_config_settings.py:0
#, python-format
msgid "Use date"
msgstr ""
2 changes: 2 additions & 0 deletions stock_production_lot_expired_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import res_config_settings
from . import stock_lot
23 changes: 23 additions & 0 deletions stock_production_lot_expired_date/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models


class ResConfig(models.TransientModel):
_inherit = "res.config.settings"

production_lot_base_date = fields.Selection(
selection="_selection_production_lot_base_date",
string="Base date to compute expiration dates",
config_parameter="stock_production_lot_expired_date.production_lot_base_date",
)

@api.model
def _selection_production_lot_base_date(self):
return [
("use", _("Use date")),
("expiration", _("Expiration date")),
("alert", _("Alert date")),
("removal", _("Removal date")),
]
57 changes: 57 additions & 0 deletions stock_production_lot_expired_date/models/stock_lot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2016-2018 Julien Coux (Camptocamp)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from dateutil.relativedelta import relativedelta

from odoo import api, models


class StockLot(models.Model):
_inherit = "stock.lot"

@api.model
def _get_product_expired_times(self, product):
return {
"expiration_time": product.expiration_time,
"use_time": product.use_time,
"removal_time": product.removal_time,
"alert_time": product.alert_time,
}

def _apply_onchange_interval_date(self, from_field):
self.ensure_one()
base_date = self.env["ir.config_parameter"].get_param(
"stock_production_lot_expired_date.production_lot_base_date"
)
if self.product_id and base_date == from_field:
if getattr(self, from_field + "_date"):
to_fields = ["alert", "expiration", "removal", "use"]
to_fields.remove(from_field)
times = self._get_product_expired_times(self.product_id)
from_time = times[from_field + "_time"]
from_date = getattr(self, from_field + "_date")
values = {}
for index in [0, 1, 2]:
if times[to_fields[index] + "_time"]:
days = from_time - times[to_fields[index] + "_time"]
values[to_fields[index] + "_date"] = from_date - relativedelta(
days=days
)
if values:
self.write(values)

@api.onchange("removal_date")
def onchange_removal_date(self):
self._apply_onchange_interval_date("removal")

@api.onchange("alert_date")
def onchange_alert_date(self):
self._apply_onchange_interval_date("alert")

@api.onchange("expiration_date")
def onchange_expiration_date(self):
self._apply_onchange_interval_date("expiration")

@api.onchange("use_date")
def onchange_use_date(self):
self._apply_onchange_interval_date("use")
2 changes: 2 additions & 0 deletions stock_production_lot_expired_date/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Julien Coux <[email protected]>
* Hughes Damry <[email protected]>
4 changes: 4 additions & 0 deletions stock_production_lot_expired_date/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module allows to facilitate the input of stock production lot expired dates:

* Add settings on stock to choose the base date for stock production lot
* Add onchanges on stock production lot to compute expired dates from base date
2 changes: 2 additions & 0 deletions stock_production_lot_expired_date/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Go to *Settings > Inventory > Traceability*
There you can set the base date under *Base date to compute expiration dates*
1 change: 1 addition & 0 deletions stock_production_lot_expired_date/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_stock_production_lot_expired_date
Loading

0 comments on commit 0071730

Please sign in to comment.