Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- models.py ---
- class MyModel(Model):
- picking = fields.Many2one(comodel_name='stock.picking')
- operations = fields.One2many(comodel_name='stock.pack.operation',
- related='return_picking.pack_operation_ids',
- readonly=True,
- states={constants.States.NEW:
- [('readonly', False)]},)
- # necessary for a second operations field in view
- operations_aux = fields.One2many(comodel_name='stock.pack.operation',
- related='operations',
- select=True)
- @api.multi
- def _get_scheduled_operations(self):
- operations = self.operations.search( # results in an empty recordset
- [('scheduled_for_operation', '=', True)])
- operations.write({'scheduled_for_operation': False}) # invalidate the ones that were retrieved
- return operations
- @api.one
- def delete_selected_operations(self):
- self._get_scheduled_operations().unlink()
- class StockPackOperationExtension(Model):
- _inherit = 'stock.pack.operation'
- scheduled_for_operation = fields.Boolean(default=False)
- --- xml view ---
- <button type="object" name="delete_selected_operations" string="Delete Selected" class="oe_edit_only" attrs="{'invisible': ['!', '|', ('state','=','draft'), ('state','=','new')]}"/>
- <!-- START: OPERATIONS FIELD-->
- <!-- Operations in Edit Mode-->
- <field name="operations" class="oe_edit_only">
- <tree editable="bottom" create="false">
- <field name="scheduled_for_operation" string="Select"/> <!-- Extra field in edit mode -->
- ... bla bla other fields ...
- </tree>
- </field>
- <!-- Operations in Read Only Mode-->
- <field name="operations_aux" class="oe_read_only">
- <tree editable="bottom" create="false">
- ... bla bla fields ...
- </tree>
- </field>
- <!-- END: OPERATIONS FIELD -->
Advertisement
Add Comment
Please, Sign In to add comment