NemeXis

mymodel_select_all

May 18th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. --- models.py ---
  2. class MyModel(Model):
  3.     picking = fields.Many2one(comodel_name='stock.picking')
  4.     operations = fields.One2many(comodel_name='stock.pack.operation',
  5.                                  related='return_picking.pack_operation_ids',
  6.                                  readonly=True,
  7.                                  states={constants.States.NEW:
  8.                                          [('readonly', False)]},)
  9.  
  10.     # necessary for a second operations field in view
  11.     operations_aux = fields.One2many(comodel_name='stock.pack.operation',
  12.                                      related='operations',
  13.                                      select=True)
  14.  
  15.     @api.multi
  16.     def _get_scheduled_operations(self):
  17.         operations = self.operations.search( # results in an empty recordset
  18.             [('scheduled_for_operation', '=', True)])
  19.  
  20.         operations.write({'scheduled_for_operation': False}) # invalidate the ones that were retrieved
  21.         return operations
  22.  
  23.     @api.one
  24.     def delete_selected_operations(self):
  25.         self._get_scheduled_operations().unlink()
  26.  
  27.  
  28. class StockPackOperationExtension(Model):
  29.     _inherit = 'stock.pack.operation'
  30.  
  31.     scheduled_for_operation = fields.Boolean(default=False)
  32.  
  33. --- xml view ---
  34.  
  35. <button type="object" name="delete_selected_operations" string="Delete Selected" class="oe_edit_only" attrs="{'invisible': ['!', '|', ('state','=','draft'), ('state','=','new')]}"/>
  36.  
  37. <!-- START: OPERATIONS FIELD-->
  38. <!-- Operations in Edit Mode-->
  39. <field name="operations" class="oe_edit_only">
  40.     <tree editable="bottom" create="false">
  41.         <field name="scheduled_for_operation" string="Select"/> <!-- Extra field in edit mode -->
  42.         ... bla bla other fields ...
  43.     </tree>
  44. </field>
  45.  
  46. <!-- Operations in Read Only Mode-->
  47. <field name="operations_aux" class="oe_read_only">
  48.     <tree editable="bottom" create="false">
  49.      ... bla bla fields ...
  50.     </tree>
  51. </field>
  52. <!-- END: OPERATIONS FIELD -->
Advertisement
Add Comment
Please, Sign In to add comment