Skip to content

Commit

Permalink
Copy orderpoint views to orderpoint templates
Browse files Browse the repository at this point in the history
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
guewen committed Mar 8, 2017
1 parent 9a91bfe commit 1c07db2
Showing 1 changed file with 52 additions and 30 deletions.
82 changes: 52 additions & 30 deletions stock_orderpoint_generator/views/orderpoint_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,80 @@
<field name="name">stock.warehouse.orderpoint.template.tree</field>
<field name="model">stock.warehouse.orderpoint.template</field>
<field name="mode">primary</field>
<field name="inherit_id" ref="stock.view_warehouse_orderpoint_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name="name">Reordering Rule Templates</attribute>
</xpath>
<field name="product_max_qty" position="after">
<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"/>
</field>
<field name="product_id" position="replace"></field>
<field name="product_uom" position="replace"></field>
</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="inherit_id" ref="stock.warehouse_orderpoint_search"/>
<field name="arch" type="xml">
<xpath expr="//search" position="attributes">
<attribute name="name">Reordering Rule Templates</attribute>
</xpath>
<field name="product_id" position="replace"></field>
<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="mode">primary</field>
<field name="inherit_id" ref="stock.view_warehouse_orderpoint_form"/>
<field name="arch" type="xml">
<xpath expr="//form" position="attributes">
<attribute name="name">Reordering Rule Templates</attribute>
</xpath>
<field name="product_id" position="replace"></field>
<field name="active" position="after">
<field name="auto_generate"/>
</field>

<sheet position="before">
<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>
<xpath expr="//sheet/group[2]" position="inside">
<group string="Automatic Rules" name="auto_rules" attrs="{'invisible': [('auto_generate', '=', False)]}">
<field name="auto_product_ids"/>
</group>
</xpath>
<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>

Expand Down

0 comments on commit 1c07db2

Please sign in to comment.