You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.4 KiB

  1. Actions must be configured with the following data in the context:
  2. * model: Model where we can find the method (required)
  3. * method: Method to execute (required)
  4. * res_id: Id as base (optional)
  5. The method must return an action. For example
  6. Action example::
  7. <act_window id="sale_order_find"
  8. name="Find Sale Order"
  9. res_model="barcode.action"
  10. view_mode="form"
  11. view_type="form"
  12. context="{'default_model': 'sale.order', 'default_method': 'find_sale_order_by_barcode'}"
  13. target="new"/>
  14. Python example::
  15. @api.multi
  16. def find_sale_order_by_barcode(self, barcode):
  17. sale_order = self.search([('name', '=', barcode)])
  18. if not sale_order:
  19. action = self.env.ref('sale_order_find')
  20. result = action.read()[0]
  21. context = safe_eval(result['context'])
  22. context.update({
  23. 'default_state': 'warning',
  24. 'default_status': _('Sale Order %s cannot be found') % barcode
  25. })
  26. result['context'] = json.dumps(context)
  27. return result
  28. action = self.env.ref('sale.action_quotations')
  29. result = action.read()[0]
  30. res = self.env.ref('sale.view_order_form', False)
  31. result['views'] = [(res and res.id or False, 'form')]
  32. result['res_id'] = sale_order.id
  33. return result