为什么我的日程安排操作在 Odoo 13 中不起作用?

My schedule action does not work Odoo 13 why?

我不明白:

scheduler_demo/data/sheduler_data.xml :

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
  <data noupdate="1">
    <record id="ir_cron_scheduler_demo_action" model="ir.cron">
      <field name="name">Demo scheduler</field>
      <field name="model_id" ref="model_scheduler_demo"></field>
      <field name="state">code</field>
      <field name="code">model.process_demo_scheduler_queue()</field>
      <field name="active" eval="True"></field>
      <field name="user_id" ref="base.user_root"></field>
      <field name="interval_number">1</field>
      <field name="interval_type">days</field>
      <field name="numbercall">-1</field>
    </record>
  </data>
</odoo>

scheduler_demo/models/初始化.py :

from . import scheduler_demo

scheduler_demo/models/sheduler_demo.py :

# -*- coding: utf-8 -*-
from odoo import models, fields, api


class SchedulerDemo(models.Model):
    _name = 'scheduler.demo'

    name = fields.Char(required=True)
    number_of_updates = fields.Integer('Number of updates')

    @api.model
    def _process_demo_scheduler_queue(self):
        # Contains all records for the model scheduler.demo
        scheduler_demo_records = self.env['scheduler.demo'].search([])

        # Loop over the records one by one
        for demo_record in scheduler_demo_records:
            number_of_updates = demo_record.number_of_updates + 1

            # Update the record with the new number of updates
            demo_record.write({
                'number_of_updates': number_of_updates
            })

scheduler_demo/security/ir.model.access.csv :

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_scheduler_demo,access_scheduler_demo,model_scheduler_demo,base.group_user,1,1,1,1

scheduler_demo/views/menu.xml :

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <menuitem id="scheduler_demo_menu_root"
              name="Scheduler tutorial"
              sequence="98"></menuitem>

    <menuitem id="menu_scheduler_demo"
              name="Scheduler records"
              parent="scheduler_demo_menu_root"
              action="action_scheduler_demo_records"
              sequence="1"></menuitem>

    <record id="action_scheduler_demo_records" model="ir.actions.act_window">
        <field name="name">Scheduler records</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">scheduler.demo</field>
        <field name="search_view_id" ref="scheduler_demo_search_view"></field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create a new scheduler record by clicking on 'Create'.
            </p>
        </field>
    </record>
</odoo>

scheduler_demo/scheduler_demo.xml :

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
 <record id="scheduler_demo_tree_view" model="ir.ui.view">
 <field name="name">scheduler.demo.tree</field>
 <field name="model">scheduler.demo</field>
 <field name="arch" type="xml">
 <tree string="Scheduler records">
 <field name="name"></field>
 <field name="number_of_updates"></field>
 </tree>
 </field>
 </record>

 <record id="scheduler_demo_form_view" model="ir.ui.view">
 <field name="name">scheduler.demo.form</field>
 <field name="model">scheduler.demo</field>
 <field name="arch" type="xml">
 <form string="Scheduler record">
 <sheet>
 <group name="main_info">
 <field name="name"></field>
 <field name="number_of_updates"></field>
 <field name="write_date"></field>
 </group>
 </sheet>
 </form>
 </field>
 </record>

 <record id="scheduler_demo_search_view" model="ir.ui.view">
 <field name="name">scheduler.demo.search</field>
 <field name="model">scheduler.demo</field>
 <field name="arch" type="xml">
 <search string="Scheduler records">
 <field name="name"></field>
 <field name="number_of_updates"></field>
 </search>
 </field>
 </record>
</odoo>

scheduler_demo/__init__py :

from . import models

scheduler_demo/清单.py :

{
    'name': "scheduler_demo",
    'depends': ['base', 'web'],
    'data': [
        'security/ir.model.access.csv',
        'data/scheduler_data.xml',
        'views/scheduler_demo.xml',
        'views/menu.xml',
    ],
    'installable': True,
    'application': False,
    'auto_install': False,
}

错误:

Odoo server error

psycopg2.IntegrityError: ERREUR:  une valeur NULL viole la contrainte NOT NULL de la colonne « activity_user_type »

DETAIL:  La ligne en échec contient (586, Demo scheduler, ir.actions.server, null, null, action, list,form, 1, 2020-09-25 13:32:44.223276, 1, 2020-09-25 13:32:44.223276, ir_cron, code, 5, 394, null, model.process_demo_scheduler_queue(), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)

During handling of the above exception, another exception occurred:



Traceback (most recent call last):
  File "/opt/odoo/odoo/http.py", line 624, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo/http.py", line 310, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/opt/odoo/odoo/tools/pycompat.py", line 14, in reraise
    raise value
  File "/opt/odoo/odoo/http.py", line 669, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo/http.py", line 350, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo/http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo/http.py", line 915, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo/http.py", line 515, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/addons/web/controllers/main.py", line 1326, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/addons/web/controllers/main.py", line 1314, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 387, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 374, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "<decorator-gen-65>", line 2, in button_immediate_upgrade
  File "/opt/odoo/odoo/addons/base/models/ir_module.py", line 72, in check_and_log
    return method(self, *args, **kwargs)
  File "/opt/odoo/odoo/addons/base/models/ir_module.py", line 634, in button_immediate_upgrade
    return self._button_immediate_function(type(self).button_upgrade)
  File "/opt/odoo/odoo/addons/base/models/ir_module.py", line 573, in _button_immediate_function
    modules.registry.Registry.new(self._cr.dbname, update_module=True)
  File "/opt/odoo/odoo/modules/registry.py", line 86, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/opt/odoo/odoo/modules/loading.py", line 419, in load_modules
    force, status, report, loaded_modules, update_module, models_to_check)
  File "/opt/odoo/odoo/modules/loading.py", line 315, in load_marked_modules
    perform_checks=perform_checks, models_to_check=models_to_check
  File "/opt/odoo/odoo/modules/loading.py", line 225, in load_module_graph
    load_data(cr, idref, mode, kind='data', package=package, report=report)
  File "/opt/odoo/odoo/modules/loading.py", line 68, in load_data
    tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
  File "/opt/odoo/odoo/tools/convert.py", line 736, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "/opt/odoo/odoo/tools/convert.py", line 803, in convert_xml_import
    obj.parse(doc.getroot())
  File "/opt/odoo/odoo/tools/convert.py", line 721, in parse
    exc_info[2]
  File "/opt/odoo/odoo/tools/pycompat.py", line 13, in reraise
    raise value.with_traceback(tb)
  File "/opt/odoo/odoo/tools/convert.py", line 712, in parse
    self._tag_root(de)
  File "/opt/odoo/odoo/tools/convert.py", line 674, in _tag_root
    f(rec)
  File "/opt/odoo/odoo/tools/convert.py", line 674, in _tag_root
    f(rec)
  File "/opt/odoo/odoo/tools/convert.py", line 577, in _tag_record
   record = model._load_records([data], self.mode == 'update')
  File "/opt/odoo/odoo/models.py", line 4084, in _load_records
    records = self._load_records_create([data['values'] for data in to_create])
  File "/opt/odoo/odoo/models.py", line 3998, in _load_records_create
    return self.create(values)
  File "<decorator-gen-40>", line 2, in create
  File "/opt/odoo/odoo/api.py", line 317, in _model_create_single
    return self.browse().concat(*(create(self, vals) for vals in arg))
  File "/opt/odoo/odoo/api.py", line 317, in <genexpr>
    return self.browse().concat(*(create(self, vals) for vals in arg))
  File "/opt/odoo/odoo/addons/base/models/ir_cron.py", line 71, in create
    return super(ir_cron, self).create(values)
  File "<decorator-gen-3>", line 2, in create
  File "/opt/odoo/odoo/api.py", line 335, in _model_create_multi
    return create(self, [arg])
  File "/opt/odoo/odoo/models.py", line 3740, in create
    for data in parent_data_list
  File "<decorator-gen-34>", line 2, in create
  File "/opt/odoo/odoo/api.py", line 336, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/odoo/addons/base/models/ir_actions.py", line 59, in create
    res = super(IrActions, self).create(vals_list)
  File "<decorator-gen-3>", line 2, in create
  File "/opt/odoo/odoo/api.py", line 336, in _model_create_multi
    return create(self, arg)
  File "/opt/odoo/odoo/models.py", line 3746, in create
    records = self._create(data_list)
  File "/opt/odoo/odoo/models.py", line 3832, in _create
    cr.execute(query, params)
  File "/opt/odoo/odoo/sql_db.py", line 168, in wrapper
    return f(self, *args, **kwargs)
  File "/opt/odoo/odoo/sql_db.py", line 245, in execute
    res = self._obj.execute(query, params)

odoo.tools.convert.ParseError: "ERREUR:  une valeur NULL viole la contrainte NOT NULL de la colonne « activity_user_type »
DETAIL:  La ligne en échec contient (586, Demo scheduler, ir.actions.server, null, null, action, list,form, 1, 2020-09-25 13:32:44.223276, 1, 2020-09-25 13:32:44.223276, ir_cron, code, 5, 394, null, model.process_demo_scheduler_queue(), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)
" while parsing /home/brenda/Code/app_odoo/scheduler_demo/data/scheduler_data.xml:2, near

<odoo>
  <data noupdate="1">
    <record id="ir_cron_scheduler_demo_action" model="ir.cron">
      <field name="name">Demo scheduler</field>
      <field name="model_id" ref="model_scheduler_demo"/>
      <field name="state">code</field>
      <field name="code">model.process_demo_scheduler_queue()</field>
      <field name="active" eval="True"/>
      <field name="user_id" ref="base.user_root"/>
      <field name="interval_number">1</field>
      <field name="interval_type">days</field>
      <field name="numbercall">-1</field>
    </record>
  </data>
</odoo>

我不明白错误,我测试了很多修改都没有成功,请有人帮助我。

Odoo 定义 ir_actions_server_id 字段(在 ir.crom 模型中)并将 delegate 属性设置为 True(对应于 _inherits),这意味着 ir.actions.server 个字段在 ir.cron 模型中可用。

activity_user_type字段在mail(添加到模块依赖)模块中定义为必填字段,默认设置为specific,所以不会出现上面的错误使用默认实现。

您可以通过继承 ir.actions.server 模型并更改必填字段的 default 属性(将其设置为 False)来重现类似的错误。

以下代码将引发 odoo.tools.convert.ParseError

class IrActionsServer(models.Model):
    _inherit = 'ir.actions.server'

    usage = fields.Selection(default=False)

它也可能是重写 create 方法并将 activity_user_type 的值设置为另一个字段值,最终计算为 False.

的结果