Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2331 Lượt xem

Hi All,

I am trying to schedule an action everyday at 15:00 o clock to automate the confirmation of po.


i create a new scheduled action with this python code but it gives me an error:


this is the code:


from odoo import models, fields
class PurchaseOrder(models.Model):
   _name = 'purchase.order'
   def action_confirm(self):
   for rec in self:
        if rec.state == 'draft' or rec.state == 'sent':                

​ ​rec.button_confirm()



And this is the error:


forbidden opcode(s) in "# Available variables:\n# - env: Odoo Environment on which the action is triggered\n# - model: Odoo Model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - float_compare: Odoo function to compare floats based on specific precisions\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - UserError: Warning Exception to use with raise\n# - Command: x2Many commands namespace\n# To return an action, assign: action = {...}\nfrom odoo import models, fields\nclass PurchaseOrder(models.Model):\n _name = 'purchase.order'\n def action_confirm(self):\n for rec in self:\n if rec.state == 'draft' or rec.state == 'sent':\n rec.button_confirm()": IMPORT_NAME, IMPORT_FROM, LOAD_BUILD_CLASS


Can anybody help me to correct the code?


Thanks in advance.


Kind regards,


Chris

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi


Try this code

for rec in env['purchase.order'].sudo().search([('state','in',('draft','sent'))]):

​rec.button_confirm()




Regards

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Now i get this error:


forbidden opcode(s) in "# Available variables:\n# - env: Odoo Environment on which the action is triggered\n# - model: Odoo Model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - float_compare: Odoo function to compare floats based on specific precisions\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - UserError: Warning Exception to use with raise\n# - Command: x2Many commands namespace\n# To return an action, assign: action = {...}\nclass PurchaseOrder(models.Model):\n _inherit = 'purchase.order'\n \n def action_confirm(self):\n vals = self.search([])\n for rec in vals:\n if rec.state == 'draft' or rec.state == 'sent':\n rec.button_confirm()": LOAD_BUILD_CLASS

Ảnh đại diện
Huỷ bỏ

Are you trying from a custom module or from odoo ui ?

Tác giả

from odoo ui in the python code section.

Tác giả

Anybody that can help me get this working? I would realy appreciate it.

Can you please try with the updated answer ?

Tác giả

Hi Bella the updated code is indeed working. Thanks for your help!!

Kind Regards,

Chris