Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WMS][12.0] Add stock_move_location_dest_constraint_tag - alpha version #698

2 changes: 2 additions & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# list the OCA project dependencies, one per line
# add a github url if you need a forked version
stock-logistics-warehouse https://github.com/grindtildeath/stock-logistics-warehouse 12.0_add_stock_move_location_dest_constraint_base
account-analytic
product-attribute
server-ux
web
stock-logistics-warehouse https://github.com/grindtildeath/stock-logistics-warehouse 12.0_add_stock_putaway_rule
79 changes: 79 additions & 0 deletions stock_move_location_dest_constraint_tag/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
========================================
Stock Move Location Dest Constraints Tag
========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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%2Fcrm-lightgray.png?logo=github
:target: https://github.com/OCA/crm/tree/12.0/stock_move_location_dest_constraint_tag
:alt: OCA/crm
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/crm-12-0/crm-12-0-stock_move_location_dest_constraint_tag
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/111/12.0
:alt: Try me on Runbot

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

This module implements destination location constraint on stock move line.

When installed stock moves will only be allowed if the destination location
includes the same tags as defined on the product or its product category.

N.B.: If tags are defined on the product, tags defined on its product category
will not be considered

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/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/crm/issues/new?body=module:%20stock_move_location_dest_constraint_tag%0Aversion:%2012.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

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

* Akim Juillerat <akim.juillerat@camptocamp.com>

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/crm <https://github.com/OCA/crm/tree/12.0/stock_move_location_dest_constraint_tag>`_ 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_move_location_dest_constraint_tag/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
30 changes: 30 additions & 0 deletions stock_move_location_dest_constraint_tag/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
{
"name": "Stock Move Location Dest Constraints Tag",
"summary": "Constrain location dest according to product tags",
"version": "12.0.1.0.0",
"development_status": "Alpha",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"stock_move_location_dest_constraint_base",
],
"data": [
"security/ir.model.access.csv",
"views/product_storage_tag.xml",
"views/product_template.xml",
"views/stock_location.xml",
],
"demo": [
"demo/product_storage_tag.xml",
"demo/product_category.xml",
"demo/product.xml",
"demo/stock_location.xml",
"demo/product_putaway.xml",
],
}
53 changes: 53 additions & 0 deletions stock_move_location_dest_constraint_tag/demo/product.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use odoo noupdate="1"


<record id="product_product_sulfuric_acid" model="product.product">
<field name="name">Sulfuric Acid</field>
<field name="categ_id" ref="product_category_acid"/>
<field name="standard_price">9.0</field>
<field name="list_price">10.0</field>
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_litre"/>
<field name="uom_po_id" ref="uom.product_uom_litre"/>
</record>
<record id="product_product_phosphoric_acid" model="product.product">
<field name="name">Phosphoric Acid</field>
<field name="categ_id" ref="product_category_acid"/>
<field name="standard_price">9.0</field>
<field name="list_price">10.0</field>
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_litre"/>
<field name="uom_po_id" ref="uom.product_uom_litre"/>
</record>

<record id="product_product_ammonium_nitrate" model="product.product">
<field name="name">Ammonium Nitrate</field>
<field name="categ_id" ref="product_category_dangerous"/>
<field name="standard_price">9.0</field>
<field name="list_price">10.0</field>
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_litre"/>
<field name="uom_po_id" ref="uom.product_uom_litre"/>
<field name="product_storage_tag_ids" eval="[(6,0,[ref('tag_dangerous'), ref('tag_cold')])]" />
</record>
<record id="product_product_tnt" model="product.product">
<field name="name">TNT</field>
<field name="categ_id" ref="product_category_dangerous"/>
<field name="standard_price">18.0</field>
<field name="list_price">20.0</field>
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_gram"/>
<field name="uom_po_id" ref="uom.product_uom_gram"/>
</record>

<record id="product_product_ice_cream" model="product.product">
<field name="name">Ice cream</field>
<field name="categ_id" ref="product.product_category_all"/>
<field name="standard_price">2.0</field>
<field name="list_price">2.5</field>
<field name="type">product</field>
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="product_storage_tag_ids" eval="[(6,0,[ref('tag_cold')])]" />
</record>
</odoo>
14 changes: 14 additions & 0 deletions stock_move_location_dest_constraint_tag/demo/product_category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noupdate="1" is missing for all demo files

<record id="product_category_acid" model="product.category">
<field name="parent_id" ref="product.product_category_all"/>
<field name="name">Acids</field>
<field name="product_storage_tag_ids" eval="[(6,0,[ref('tag_liquid'), ref('tag_dangerous')])]" />
</record>
<record id="product_category_dangerous" model="product.category">
<field name="parent_id" ref="product.product_category_all"/>
<field name="name">Dangerous</field>
<field name="product_storage_tag_ids" eval="[(6,0,[ref('tag_dangerous')])]" />
</record>

</odoo>
23 changes: 23 additions & 0 deletions stock_move_location_dest_constraint_tag/demo/product_putaway.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="putaway_strat_acid_category" model="stock.putaway.rule">
<field name="category_id" ref="product_category_acid" />
<field name="location_in_id" ref="stock.stock_location_stock" />
<field name="location_out_id" ref="location_bin_acids" />
</record>
<record id="putaway_strat_dangerous_category" model="stock.putaway.rule">
<field name="category_id" ref="product_category_dangerous" />
<field name="location_in_id" ref="stock.stock_location_stock" />
<field name="location_out_id" ref="location_bin_dangerous" />
</record>
<record id="putaway_strat_ice_cream_product" model="stock.putaway.rule">
<field name="product_id" ref="product_product_ice_cream" />
<field name="location_in_id" ref="stock.stock_location_stock" />
<field name="location_out_id" ref="stock.location_refrigerator_small" />
</record>
<record id="putaway_strat_ammonium_product" model="stock.putaway.rule">
<field name="product_id" ref="product_product_ammonium_nitrate" />
<field name="location_in_id" ref="stock.stock_location_stock" />
<field name="location_out_id" ref="location_freezer_dangerous" />
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="tag_dangerous" model="product.storage.tag">
<field name="sequence">10</field>
<field name="name">Dangerous</field>
</record>
<record id="tag_cold" model="product.storage.tag">
<field name="sequence">20</field>
<field name="name">Cold</field>
</record>
<record id="tag_hot" model="product.storage.tag">
<field name="sequence">30</field>
<field name="name">Hot</field>
</record>
<record id="tag_liquid" model="product.storage.tag">
<field name="sequence">40</field>
<field name="name">Liquid</field>
</record>
</odoo>
25 changes: 25 additions & 0 deletions stock_move_location_dest_constraint_tag/demo/stock_location.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="stock.location_refrigerator_small" model="stock.location">
<field name="product_storage_tag_ids" eval="[(6,0,[ref('tag_cold')])]" />
<field name="bypass_constraints" eval="False" />
</record>
<record id="location_freezer_dangerous" model="stock.location">
<field name="name">Freezer for dangerous goods</field>
<field name="usage">internal</field>
<field name="location_id" ref="stock.stock_location_14"/>
<field name="product_storage_tag_ids" eval="[(6,0,[ref('tag_cold'), ref('tag_dangerous')])]" />
</record>
<record id="location_bin_acids" model="stock.location">
<field name="name">Acids Bin</field>
<field name="usage">internal</field>
<field name="location_id" ref="stock.stock_location_components"/>
<field name="product_storage_tag_ids" eval="[(6,0,[ref('tag_liquid'), ref('tag_dangerous')])]" />
</record>
<record id="location_bin_dangerous" model="stock.location">
<field name="name">Dangerous Bin</field>
<field name="usage">internal</field>
<field name="location_id" ref="stock.stock_location_components"/>
<field name="product_storage_tag_ids" eval="[(6,0,[ref('tag_dangerous')])]" />
</record>
</odoo>
4 changes: 4 additions & 0 deletions stock_move_location_dest_constraint_tag/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import product_category
from . import product_storage_tag
from . import product_template
from . import stock_location
13 changes: 13 additions & 0 deletions stock_move_location_dest_constraint_tag/models/product_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import models, fields

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import should be in alphabetical order
from odoo import fields, models



class ProductCategory(models.Model):

_inherit = 'product.category'

product_storage_tag_ids = fields.Many2many(
'product.storage.tag',
string='Storage Tags',
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import models, fields

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above



class ProductStorageTag(models.Model):

_name = 'product.storage.tag'
_description = 'Storage tag'

sequence = fields.Integer(default=10)
name = fields.Char(required=True)
13 changes: 13 additions & 0 deletions stock_move_location_dest_constraint_tag/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import models, fields

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above



class ProductTemplate(models.Model):

_inherit = 'product.template'

product_storage_tag_ids = fields.Many2many(
'product.storage.tag',
string='Storage Tags',
)
37 changes: 37 additions & 0 deletions stock_move_location_dest_constraint_tag/models/stock_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import models, fields, _

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be from odoo import _, fields, models

from odoo.exceptions import ValidationError


class StockLocation(models.Model):

_inherit = 'stock.location'

product_storage_tag_ids = fields.Many2many(
'product.storage.tag',
string='Storage Tags',
)

def check_move_dest_constraint(self, line=None, product=None):
res = super().check_move_dest_constraint(line=line, product=product)
if product:
product_tags = product.product_storage_tag_ids
if not product_tags:
product_tags = product.categ_id.product_storage_tag_ids
if (
product_tags and
not product_tags <= self.product_storage_tag_ids
):
raise ValidationError(_(
'Tags mismatch between product tags requirements %s (%s)'
' and location tags allowed %s (%s)' % (
product.name,
','.join(
product.product_storage_tag_ids.mapped('name')
),
self.name,
','.join(self.product_storage_tag_ids.mapped('name'))
)
))
return res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Akim Juillerat <akim.juillerat@camptocamp.com>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This module implements destination location constraint on stock move line.

When installed stock moves will only be allowed if the destination location
includes the same tags as defined on the product or its product category.

N.B.: If tags are defined on the product, tags defined on its product category
will not be considered
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_product_storage_tag,access_product_storage_tag,model_product_storage_tag,base.group_user,1,0,0,0
access_product_storage_tag_stock_user,access_product_storage_tag_stock_user,model_product_storage_tag,stock.group_stock_user,1,1,1,1
Loading