forked from OCA/stock-logistics-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] stock_orderpoint_generator: Add Automatic Reordering Rules (OCA…
…#258) And improve the wording * Add an option to automatically generate rules When a product variant is created with a (or several) rule template(s), it automatically generates (on the fly) the corresponding rule(s). When a rule template is modified, it automatically updates the existing rules of the linked products (it uses the mechanism in place, disable the old and create a fresh one). The latter update is done by a cron because it might take a long time to update all the products reordering rules. * Add documentation * Copy orderpoint views to orderpoint templates Unfortunately we cannot rely on the possibility to copy a view with "inherit_id" + "mode=primary" in Odoo 9.0 in this use case (precisely with a model that is a "copy by prototype"). The explanation: We "copy by prototype" the model "stock.warehouse.orderpoint" to a new "stock.warehouse.orderpoint.template" model (with both _inherit and different _name). Before this commit, we were reusing the stock.warehouse.orderpoint's views, just making the changes needed for the templates. Thing is: when a third (unrelated) addon adds a column on the model, the ORM doesn't add the column in the stock.warehouse.orderpoint.template model. So the templates' views complains about this unexisting field. Therefore, copy-pasting the view ensure that changes on 'stock.warehouse.orderpoint' does not have any side effect on the templates. From Odoo 10.0, the "copy by prototype" reports the changes made on the "prototype" model to the "copy" so we should be able to revert to the "inherit_id" + "mode=primary" views.
- Loading branch information
Showing
10 changed files
with
245 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,40 @@ | |
Order point generator | ||
===================== | ||
|
||
Add a wizard to configure order points for multiple products in one go. | ||
Add a wizard to configure reordering rules for multiple products in one go, | ||
and allow to automatically update reordering rules from rule templates. | ||
|
||
Configuration | ||
============= | ||
|
||
Reordering rule templates can be configured in "Inventory > Configuration > | ||
Products > Reordering Rule Templates". | ||
|
||
The frequency of the cron that updates the Reordering Rules can be configured | ||
in "Settings > Technical > Actions > Scheduled Actions". The name of the | ||
scheduled action is "Reordering Rule Templates Generator". | ||
|
||
Usage | ||
===== | ||
|
||
By activating the "Create Rules Automatically" on a reordering rule template, | ||
you are able to select a list of products. Any change on the template will then | ||
be replicated on the products Reordering Rules. The change is not immediate as | ||
it is processed by a scheduled action. | ||
|
||
On a product, you can also choose one or more Reordering Rule Templates. Any | ||
template added or removed on the product is immediately reflected on its | ||
Reordering Rules. | ||
|
||
Lastly, you can promptly create Reordering Rules for a product or a product | ||
template using the "Reordering Rules Generator". Note that it will replace all | ||
the existing rules for the product. You will usually not want to use this | ||
feature on products that have Automatic Reordering Rules Templates. | ||
|
||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/153/9.0 | ||
|
||
|
||
Bug Tracker | ||
|
@@ -22,9 +55,11 @@ Credits | |
|
||
Contributors | ||
------------ | ||
|
||
* Yannick Vaucher <[email protected]> | ||
* Matthieu Dietrich <[email protected]> | ||
* Cyril Gaudin <[email protected]> | ||
* Guewen Baconnier <[email protected]> | ||
|
||
Maintainer | ||
---------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo noupdate="1"> | ||
|
||
<record id="ir_cron_auto_orderpoint_template" model="ir.cron"> | ||
<field name="name">Reordering Rule Templates Generator</field> | ||
<field name="interval_number">1</field> | ||
<field name="interval_type">hours</field> | ||
<field name="numbercall">-1</field> | ||
<field eval="False" name="doall"/> | ||
<field eval="'stock.warehouse.orderpoint.template'" name="model"/> | ||
<field eval="'_cron_create_auto_orderpoints'" name="function"/> | ||
<field eval="'()'" name="args"/> | ||
<field name="active" eval="True" /> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import orderpoint_template | ||
from . import product |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from openerp import api, fields, models | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = 'product.product' | ||
|
||
auto_orderpoint_template_ids = fields.Many2many( | ||
comodel_name='stock.warehouse.orderpoint.template', | ||
string="Automatic Reordering Rules", | ||
domain=[('auto_generate', '=', True)], | ||
help="When one or several automatic reordering rule is selected, " | ||
"a Scheduled Action will automatically generate or update " | ||
"the reordering rules of the product." | ||
) | ||
|
||
@api.model | ||
def create(self, vals): | ||
record = super(ProductProduct, self).create(vals) | ||
if vals.get('auto_orderpoint_template_ids'): | ||
record.auto_orderpoint_template_ids.create_orderpoints(record.ids) | ||
return record | ||
|
||
@api.multi | ||
def write(self, vals): | ||
result = super(ProductProduct, self).write(vals) | ||
if vals.get('auto_orderpoint_template_ids'): | ||
orderpoint_templates = self.mapped('auto_orderpoint_template_ids') | ||
orderpoint_templates.create_orderpoints(self.ids) | ||
return result |
106 changes: 106 additions & 0 deletions
106
stock_orderpoint_generator/views/orderpoint_template_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="view_warehouse_orderpoint_template_tree" model="ir.ui.view"> | ||
<field name="name">stock.warehouse.orderpoint.template.tree</field> | ||
<field name="model">stock.warehouse.orderpoint.template</field> | ||
<field name="mode">primary</field> | ||
<field name="arch" type="xml"> | ||
<tree string="Reordering Rule Templates"> | ||
<field name="name"/> | ||
<field name="warehouse_id" groups="stock.group_locations"/> | ||
<field name="location_id" groups="stock.group_locations"/> | ||
<field name="product_min_qty"/> | ||
<field name="product_max_qty"/> | ||
<field name="auto_generate"/> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record model="ir.ui.view" id="view_warehouse_orderpoint_template_search"> | ||
<field name="name">stock.warehouse.orderpoint.template.search</field> | ||
<field name="model">stock.warehouse.orderpoint.template</field> | ||
<field name="mode">primary</field> | ||
<field name="arch" type="xml"> | ||
<search string="Reordering Rule Templates Search"> | ||
<field name="name" string="Reordering Rule Templates"/> | ||
<field name="warehouse_id"/> | ||
<field name="location_id" groups="stock.group_locations"/> | ||
<field name="company_id" groups="base.group_multi_company"/> | ||
<group expand="0" string="Group By"> | ||
<filter string="Warehouse" domain="[]" context="{'group_by':'warehouse_id'}"/> | ||
<filter string="Location" domain="[]" context="{'group_by':'location_id'}"/> | ||
</group> | ||
</search> | ||
</field> | ||
</record> | ||
|
||
<record id="view_warehouse_orderpoint_template_form" model="ir.ui.view"> | ||
<field name="name">stock.warehouse.orderpoint.template.form</field> | ||
<field name="model">stock.warehouse.orderpoint.template</field> | ||
<field name="arch" type="xml"> | ||
<form string="Reordering Rule Template"> | ||
<header> | ||
<button name="create_auto_orderpoints" type="object" string="Generate Automatic Rules" | ||
help="Reordering rules will be created for the selected products. This is equivalent to the Scheduled Action action." | ||
attrs="{'invisible': [('auto_generate', '=', False)]}"/> | ||
</header> | ||
<sheet> | ||
<group> | ||
<group> | ||
<field name="name" /> | ||
</group> | ||
<group> | ||
<field name="warehouse_id" on_change="onchange_warehouse_id(warehouse_id)" widget="selection" groups="stock.group_locations"/> | ||
<field name="location_id" groups="stock.group_locations"/> | ||
<field name="group_id" groups="stock.group_adv_location"/> | ||
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/> | ||
</group> | ||
</group> | ||
<group> | ||
<group string="Rules"> | ||
<field name="product_min_qty" /> | ||
<field name="product_max_qty" /> | ||
<field name="qty_multiple" string="Quantity Multiple"/> | ||
</group> | ||
<group string="Misc"> | ||
<field name="active" /> | ||
<field name="auto_generate"/> | ||
<label for="lead_days"/> | ||
<div class="o_row"> | ||
<field name="lead_days"/> | ||
<field name="lead_type"/> | ||
</div> | ||
</group> | ||
<group string="Automatic Rules" name="auto_rules" attrs="{'invisible': [('auto_generate', '=', False)]}"> | ||
<field name="auto_product_ids"/> | ||
</group> | ||
</group> | ||
</sheet> | ||
</form> | ||
|
||
</field> | ||
</record> | ||
|
||
<record id="action_orderpoint_template" model="ir.actions.act_window"> | ||
<field name="name">Reordering Rule Templates</field> | ||
<field name="res_model">stock.warehouse.orderpoint.template</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="view_type">form</field> | ||
<field name="view_mode">tree,form</field> | ||
<field name="view_id" ref="view_warehouse_orderpoint_template_tree"/> | ||
<field name="search_view_id" ref="view_warehouse_orderpoint_template_search" /> | ||
<field name="help" type="html"> | ||
<p class="oe_view_nocontent_create"> | ||
Click to add a reordering rule template. | ||
</p> | ||
</field> | ||
</record> | ||
|
||
<menuitem | ||
id="menu_orderpoint_template" name="Reordering Rule Templates" | ||
parent="stock.menu_product_in_config_stock" | ||
action="action_orderpoint_template" | ||
/> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="product_normal_form_view" model="ir.ui.view"> | ||
<field name="name">product.product.form</field> | ||
<field name="model">product.product</field> | ||
<field name="inherit_id" ref="product.product_normal_form_view"/> | ||
<field name="arch" type="xml"> | ||
<field name="seller_ids" position="before"> | ||
<separator string="Automatic Reordering Rules"/> | ||
<field name="auto_orderpoint_template_ids" context="{'default_auto_generate': True}"/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters