[IMP] stock: product view usability

Route diagram directly open with a single warehouse and variant.
Move fields and group to have a cleaner view.

Task: 2161378
This commit is contained in:
Arnold Moyaux
2020-04-22 08:03:15 +00:00
parent 3f2815ab2f
commit db978e3609
2 changed files with 37 additions and 7 deletions
+17
View File
@@ -785,6 +785,23 @@ class ProductTemplate(models.Model):
})
return action
def action_open_routes_diagram(self):
products = False
if self.env.context.get('default_product_id'):
products = self.env['product.product'].browse(self.env.context['default_product_id'])
if not products and self.env.context.get('default_product_tmpl_id'):
products = self.env['product.template'].browse(self.env.context['default_product_tmpl_id']).product_variant_ids
if not self.user_has_groups('stock.group_stock_multi_warehouses') and len(products) == 1:
company = products.company_id or self.env.company
warehouse = self.env['stock.warehouse'].search([('company_id', '=', company.id)], limit=1)
return self.env.ref('stock.action_report_stock_rule').report_action(None, data={
'product_id': products.id,
'warehouse_ids': warehouse.ids,
})
action = self.env.ref('stock.action_stock_rules_report').read()[0]
action['context'] = self.env.context
return action
def action_product_tmpl_forecast_report(self):
action = self.env.ref('stock.report_stock_quantity_action_product').read()[0]
product_ids = self.with_context(active_test=False).product_variant_ids.filtered(lambda p: p.virtual_available != 0)
+20 -7
View File
@@ -23,6 +23,15 @@
</field>
</record>
<record model="ir.actions.server" id="action_open_routes">
<field name="name">Routes</field>
<field name="model_id" ref="product.model_product_template"/>
<field name="state">code</field>
<field name="code">
action = model.action_open_routes_diagram()
</field>
</record>
<record id="view_stock_product_tree" model="ir.ui.view">
<field name="name">product.stock.tree.inherit</field>
<field name="model">product.product</field>
@@ -94,21 +103,25 @@
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='group_lots_and_weight']" position="inside">
<label for="sale_delay" attrs="{'invisible': [('sale_ok', '=', False)]}"/>
<div attrs="{'invisible': [('sale_ok', '=', False)]}">
<field name="sale_delay" class="oe_inline" style="vertical-align:baseline"/> days
</div>
</xpath>
<xpath expr="//group[@name='group_lots_and_weight']" position="before">
<group string="Operations" name="operations">
<label for="route_ids" attrs="{'invisible': [('type', 'in', ['service', 'digital'])]}"/>
<div>
<field name="route_ids" class="mb-0" widget="many2many_checkboxes" attrs="{'invisible': [('type', 'in', ['service', 'digital'])]}"/>
<button string="See routes diagram" type="action" name="%(action_stock_rules_report)d" icon="fa-cogs"
<button string="View Diagram" type="action" name="%(action_open_routes)d" icon="fa-arrow-right"
attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}"
class="btn btn-link pt-0" context="{'default_product_tmpl_id': id}"/>
</div>
<field name="route_from_categ_ids" widget="many2many_tags" readonly="1" attrs="{'invisible': [('route_from_categ_ids', '=', [])]}"/>
<label for="sale_delay" attrs="{'invisible': [('sale_ok', '=', False)]}"/>
<div attrs="{'invisible': [('sale_ok', '=', False)]}">
<field name="sale_delay" class="oe_inline" style="vertical-align:baseline"/> days
</div>
</group>
</xpath>
<xpath expr="//group[@name='group_lots_and_weight']" position="after">
<group string="Traceability" name="traceability" groups="stock.group_production_lot"
attrs="{'invisible': [('type', '=', 'consu')]}">
<field name="tracking" widget="radio" attrs="{'invisible': [('type', 'in', ['service', 'digital'])]}"/>
@@ -270,7 +283,7 @@
attrs="{'invisible': [('type', '=', 'service')]}"
context="{'invisible_handle': True, 'single_product': True}"/>
</div>
<xpath expr="//button[@name='%(action_stock_rules_report)d']" position="attributes">
<xpath expr="//button[@name='%(action_open_routes)d']" position="attributes">
<attribute name="context">
{'default_product_id': id}
</attribute>
@@ -369,7 +382,7 @@
<attribute name="attrs">{'invisible': [('type', 'not in', ['product', 'consu'])]}</attribute>
</xpath>
<xpath expr="//group[@name='group_lots_and_weight']" position="inside">
<xpath expr="//label[@for='weight']" position="before">
<field name="responsible_id" domain="[('share', '=', False)]"/>
</xpath>
</data>