from odoo.tools.profiler import profile [...] @profile @api.model defmymethod(...):
实战姿势:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
@profile defaction_confirm(self): if self._get_forbidden_state_confirm() & set(self.mapped('state')): raise UserError(_( 'It is not allowed to confirm an order in the following states: %s' ) % (', '.join(self._get_forbidden_state_confirm())))
for order in self.filtered(lambda order: order.partner_id notin order.message_partner_ids): order.message_subscribe([order.partner_id.id]) self.write({ 'state': 'sale', 'date_order': fields.Datetime.now() }) self._action_confirm() if self.env.user.has_group('sale.group_auto_done_setting'): self.action_done() returnTrue