[FIX] mrp: customize unbuild form via manufacturing order
When unbuilding a manufacturing order, there are fields in the default unbuild form that do not make sense to show (i.e. they already correspond to the manufacturing order that is triggering the unbuild). Therefore we make a simplified version of this form that is better suited for a button generated window. This change includes removing the resetting of 'location_id' and 'location_dest_id' when they correspond to the 'company_id' by onchange function since this would overwrite any 'default_location_id' and 'location_dest_id' values when calling the view + this seemed like it would be annoying if someone clicks on the same 'company_id' within the dropdown and their location values changed. closes odoo/odoo#49514 Task: 2234872 X-original-commit: d23341a5b4cb82f4a96b55464dec32dc28ce4351 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
@@ -1195,11 +1195,15 @@ class MrpProduction(models.Model):
|
||||
def button_unbuild(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'name': _('Unbuild'),
|
||||
'name': _('Unbuild: %s') % self.product_id.display_name,
|
||||
'view_mode': 'form',
|
||||
'res_model': 'mrp.unbuild',
|
||||
'view_id': self.env.ref('mrp.mrp_unbuild_form_view').id,
|
||||
'view_id': self.env.ref('mrp.mrp_unbuild_form_view_simplified').id,
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': {'default_mo_id': self.id, 'create': False, 'edit': False},
|
||||
'context': {'default_mo_id': self.id,
|
||||
'default_company_id': self.company_id.id,
|
||||
'default_location_id': self.location_dest_id.id,
|
||||
'default_location_dest_id': self.location_src_id.id,
|
||||
'create': False, 'edit': False},
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
@@ -96,8 +96,10 @@ class MrpUnbuild(models.Model):
|
||||
def _onchange_company_id(self):
|
||||
if self.company_id:
|
||||
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.company_id.id)], limit=1)
|
||||
self.location_id = warehouse.lot_stock_id
|
||||
self.location_dest_id = warehouse.lot_stock_id
|
||||
if self.location_id.company_id != self.company_id:
|
||||
self.location_id = warehouse.lot_stock_id
|
||||
if self.location_dest_id.company_id != self.company_id:
|
||||
self.location_dest_id = warehouse.lot_stock_id
|
||||
else:
|
||||
self.location_id = False
|
||||
self.location_dest_id = False
|
||||
|
||||
@@ -130,6 +130,45 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- simplified version of unbuild form for unbuild button via manufacturing order,
|
||||
expects required fields to be filled in via 'default_' values -->
|
||||
<record id="mrp_unbuild_form_view_simplified" model="ir.ui.view">
|
||||
<field name="name">mrp.unbuild.form.simplified</field>
|
||||
<field name="model">mrp.unbuild</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Unbuild Order">
|
||||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="product_id" invisible="1"/>
|
||||
<field name="bom_id" invisible="1"/>
|
||||
<label for="product_qty"/>
|
||||
<div class="o_row">
|
||||
<field name="product_qty" attrs="{'readonly': [('has_tracking', '=', 'serial')]}"/>
|
||||
<field name="product_uom_id" options="{'no_open': True, 'no_create': True}" groups="uom.group_uom" attrs="{'readonly': [('mo_id', '!=', False)]}" force_save="1"/>
|
||||
</div>
|
||||
</group>
|
||||
<group>
|
||||
<field name="mo_id" invisible="1"/>
|
||||
<field name="location_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
|
||||
<field name="location_dest_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
|
||||
<field name="has_tracking" invisible="1"/>
|
||||
<field name="allowed_mo_ids" invisible="1"/>
|
||||
<field name="lot_id" attrs="{'invisible': [('has_tracking', '=', 'none')], 'required': [('has_tracking', '!=', 'none')]}" groups="stock.group_production_lot"/>
|
||||
<field name="company_id" groups="base.group_multi_company" readonly="1"/>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
<footer class="oe_edit_only">
|
||||
<button name="action_validate" string="Unbuild" type="object" states="draft" class="oe_highlight"/>
|
||||
<button string="Discard" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="mrp_unbuild_tree_view" model="ir.ui.view">
|
||||
<field name="name">mrp.unbuild.tree</field>
|
||||
<field name="model">mrp.unbuild</field>
|
||||
|
||||
Reference in New Issue
Block a user