Skip to content
Snippets Groups Projects
Commit 19c48161 authored by svs-odoo's avatar svs-odoo
Browse files

[IMP] *: compute to display full prod lot view

Before this commit, we had two form views for production lot: one more
complete and one simplier.
The complete one was displayed when we come from the prod lot list view,
and the simplier one in any other case.

But actually, we need to display the simplier one only with "Create and
Edit" and display the complete one in any other case, but it's
impossible to do with only two distinguish views.

So, we keep only one view with all elements and we display or hide some
fields or button in function of the context or if the record is new.

Task #1935921
parent e23a876a
No related branches found
No related tags found
No related merge requests found
......@@ -24,30 +24,6 @@
</field>
</record>
<record id="view_move_form_expiry_simple" model="ir.ui.view">
<field name="name">stock.production.lot.inherit.form</field>
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form_simple" />
<field name="arch" type="xml">
<xpath expr="//group[@name='main_group']" position="after">
<group string="Dates">
<group>
<field name="use_date" />
<field name="removal_date" />
</group>
<group>
<field name="life_date" />
<field name="alert_date" />
</group>
</group>
</xpath>
<xpath expr="//div[hasclass('oe_title')]" position="inside">
<field name="product_expiry_alert" invisible="1"/>
<span class="badge badge-danger" attrs="{'invisible': [('product_expiry_alert', '=', False)]}">Expiration Alert</span>
</xpath>
</field>
</record>
<record id="search_product_lot_filter_inherit_product_expiry" model="ir.ui.view">
<field name="name">stock.production.lot.search.inherit</field>
<field name="model">stock.production.lot</field>
......
......@@ -7,7 +7,8 @@
<field name="arch" type="xml">
<xpath expr="//div[hasclass('oe_button_box')]/button" position="before">
<button class="oe_stat_button" name="action_view_po"
type="object" icon="fa-shopping-cart" attrs="{'invisible': [('purchase_order_count', '=', 0)]}" help="Purchase Orders">
type="object" icon="fa-shopping-cart" help="Purchase Orders"
attrs="{'invisible': ['|', ('purchase_order_count', '=', 0), ('display_complete', '=', False)]}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="purchase_order_count" widget="statinfo" nolabel="1" class="mr4"/>
......@@ -16,16 +17,10 @@
</div>
</button>
</xpath>
</field>
</record>
<record id="stock_production_lot_view_form_simple" model="ir.ui.view">
<field name="name">stock.production.lot.view.form.simple</field>
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form_simple"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='main_group']" position="after">
<group>
<field name="purchase_order_ids" widget="many2many" readonly="True" attrs="{'invisible': [('purchase_order_ids', '=', [])]}">
<field name="purchase_order_ids" widget="many2many" readonly="True"
attrs="{'invisible': ['|', ('purchase_order_ids', '=', []), ('display_complete', '=', True)]}">
<tree>
<field name="name"/>
<field name="partner_id"/>
......
......@@ -7,7 +7,8 @@
<field name="arch" type="xml">
<xpath expr="//div[hasclass('oe_button_box')]/button" position="before">
<button class="oe_stat_button" name="action_view_so"
type="object" icon="fa-pencil-square-o" attrs="{'invisible': [('sale_order_count', '=', 0)]}" help="Sale Orders">
type="object" icon="fa-pencil-square-o" help="Sale Orders"
attrs="{'invisible': ['|', ('sale_order_count', '=', 0), ('display_complete', '=', False)]}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="sale_order_count" widget="statinfo" nolabel="1" class="mr4"/>
......@@ -16,16 +17,10 @@
</div>
</button>
</xpath>
</field>
</record>
<record id="stock_production_lot_view_form_simple" model="ir.ui.view">
<field name="name">stock.production.lot.view.form.simple</field>
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form_simple"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='main_group']" position="after">
<group>
<field name="sale_order_ids" widget="many2many" readonly="True" attrs="{'invisible': [('sale_order_ids', '=', [])]}">
<field name="sale_order_ids" widget="many2many" readonly="True"
attrs="{'invisible': ['|', ('sale_order_ids', '=', []), ('display_complete', '=', True)]}">
<tree>
<field name="name"/>
<field name="partner_id"/>
......
......@@ -23,6 +23,7 @@ class ProductionLot(models.Model):
quant_ids = fields.One2many('stock.quant', 'lot_id', 'Quants', readonly=True)
product_qty = fields.Float('Quantity', compute='_product_qty')
note = fields.Html(string='Description')
display_complete = fields.Boolean(compute='_compute_display_complete')
_sql_constraints = [
('name_ref_uniq', 'unique (name, product_id)', 'The combination of serial number and product must be unique !'),
......@@ -35,6 +36,16 @@ class ProductionLot(models.Model):
if picking_id and not picking_id.picking_type_id.use_create_lots:
raise UserError(_('You are not allowed to create a lot or serial number with this operation type. To change this, go on the operation type and tick the box "Create New Lots/Serial Numbers".'))
@api.depends('name')
def _compute_display_complete(self):
""" Defines if we want to display all fields in the stock.production.lot form view.
It will if the record exists (`id` set) or if we precised it into the context.
This compute depends on field `name` because as it has always a default value, it'll be
always triggered.
"""
for prod_lot in self:
prod_lot.display_complete = prod_lot.id or self._context.get('display_complete')
@api.model_create_multi
def create(self, vals_list):
self._check_create()
......
......@@ -7,7 +7,9 @@
<field name="arch" type="xml">
<form string="Lots/Serial Numbers">
<sheet>
<div class="oe_button_box" name="button_box">
<field name="display_complete" invisible="1"/>
<div class="oe_button_box" name="button_box"
attrs="{'invisible': [('display_complete', '=', False)]}">
<button name="action_lot_open_quants" icon="fa-arrows" class="oe_stat_button" string="Locate" type="object"/>
<button name="%(action_stock_report)d" icon="fa-arrow-up" class="oe_stat_button" string="Traceability Report" type="action"/>
</div>
......@@ -19,16 +21,18 @@
</div>
<group name="main_group">
<group>
<field name="product_id" help="Product this lot/serial number contains. You cannot change it anymore if it has already been moved."/>
<label for="product_qty"/>
<div class="o_row">
<field name="product_qty"/>
<field name="product_uom_id" readonly="1" groups="uom.group_uom"/>
</div>
<field name="product_id"
help="Product this lot/serial number contains. You cannot change it anymore if it has already been moved."
attrs="{'readonly': [('id', '!=', False), ('product_id', '!=', False)]}"/>
<label for="product_qty" attrs="{'invisible': [('display_complete', '=', False)]}"/>
<div class="o_row" attrs="{'invisible': [('display_complete', '=', False)]}">
<field name="product_qty"/>
<field name="product_uom_id" readonly="1" groups="uom.group_uom"/>
</div>
<field name="ref"/>
</group>
</group>
<notebook>
<notebook attrs="{'invisible': [('display_complete', '=', False)]}">
<page string="Description">
<field name="note"/>
</page>
......@@ -43,33 +47,6 @@
</field>
</record>
<record id="view_production_lot_form_simple" model="ir.ui.view">
<field name="name">stock.production.lot.form.simple</field>
<field name="model">stock.production.lot</field>
<field name="priority">1</field>
<field name="arch" type="xml">
<form string="Lots/Serial Numbers">
<sheet>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name" placeholder="e.g. LOT/0001/20121"/>
</h1>
</div>
<group name="main_group">
<field name="product_id" attrs="{'readonly': [('product_id', '!=', False)]}" force_save="1" help="Product this lot/serial number contains. You cannot change it anymore if it has already been moved."/>
<field name="ref"/>
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="activity_ids" widget="mail_activity"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>
<record id="view_production_lot_tree" model="ir.ui.view">
<field name="name">stock.production.lot.tree</field>
<field name="model">stock.production.lot</field>
......@@ -105,7 +82,7 @@
(0, 0, {'view_mode': 'tree', 'view_id': ref('view_production_lot_tree')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('view_production_lot_form')})]"/>
<field name="search_view_id" ref="search_product_lot_filter"/>
<field name="context">{'search_default_group_by_product': 1}</field>
<field name="context">{'search_default_group_by_product': 1, 'display_complete': True}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Add a lot/serial number
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment