0

I have a module what lock the Sale Order. I want to do auto-triggering this function when a Field in settings is True.

Because at this moment it's call the function only when i hit a button.

There is how i check if a field value is 'set':

@api.multi
def auto_order_finishing(self):
    field_value = self.env['ir.config_parameter'].sudo().get_param('sale.activate_automate_so_locking')
    if field_value:
        self.confirm_finish_order()
return True
Naglis
  • 2,583
  • 1
  • 19
  • 24
KushiNii
  • 7
  • 8

2 Answers2

0

You can create a scheduled action to some function that calls auto_order_finishing on all relevant sale orders at a specific interval.

You can find examples of these by searching for model="ir.cron"

I've pasted an example below

<record forcecreate="True" id="ir_cron_mail_scheduler_action" model="ir.cron">
    <field name="name">Mail: Email Queue Manager</field>
    <field name="model_id" ref="model_mail_mail"/>
    <field name="state">code</field>
    <field name="code">model.process_email_queue()</field>
    <field name="user_id" ref="base.user_root"/>
    <field name="interval_number">1</field>
    <field name="interval_type">hours</field>
    <field name="numbercall">-1</field>
    <field eval="False" name="doall"/>
</record>
KbiR
  • 4,047
  • 6
  • 37
  • 103
Matt
  • 1
  • 1
  • Thank you much for answer, but i think, should be a better way – KushiNii Mar 02 '18 at 12:38
  • and one more problem, that scheduler have only "minutes" interval_type value. Even i need to trigger funciton all time when the Field is True. Because the module is check that all deliverys and invoices are closed, and if yes, only then it's lock the Sale Order automaticly – KushiNii Mar 02 '18 at 13:03
  • I'm struggling to understand exactly what you're trying to do. If it needs to be done instantly, then you can do two things to achieve this. @api.depends can trigger a function when a particular value is set, if you need to call the function on any historic sale orders. In addition to this you would override the sale order confirm function perhaps, and call your function afterwards provided that your value is set to True. – Matt Mar 05 '18 at 09:11
0

Please check server action, you can achieve your feature with that. You need to add python code & event on which that code will be applied.

Ajay Chauhan
  • 109
  • 3