创建序列号odoo 10

时间:2017-09-26 21:08:35

标签: odoo odoo-10

我想创建一个序列号odoo 10(有人认为像OM-201709-001)我使用此代码:

*。XML

<openerp>
    <data noupdate="1">
        <record id="seq_type_id" model="ir.sequence.type">
        <field name="name">omega_sequence</field>
        <field name="code">hr.employee</field>
        </record>

        <record id="seq_id" model="ir.sequence">
        <field name="name">omega_sequence</field>
        <field name="code">hr.employee</field>
        <field name="prefix">SQ</field>
        <field name="padding">5</field>
        <!--<field name="suffix">suffix</field>-->
        </record>

    </data>
</openerp>

和for:

*。PY

   
class omega(models.Model):
    _name = 'omega.model'
    _description = 'No Description for now !!'

    sequence_id = fields.Char('Sequence', readonly=True)

    @api.model
    def create(self, vals):
        seq = self.env['ir.sequence'].get('hr.employee') or '/'
        vals['sequence_id'] = seq
        return super(omega, self).create(vals)

但我总是得到这个错误:

Traceback (most recent call last):
  File "/opt/odoo/odoo/http.py", line 640, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo/http.py", line 677, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo/http.py", line 333, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo/service/model.py", line 101, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo/http.py", line 326, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo/http.py", line 935, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo/http.py", line 506, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/addons/web/controllers/main.py", line 889, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo/addons/web/controllers/main.py", line 877, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 689, in call_kw
    return call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/odoo/api.py", line 680, in call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/odoo/addons/base/module/module.py", line 410, in button_immediate_install
    return self._button_immediate_function(type(self).button_install)
  File "/opt/odoo/odoo/addons/base/module/module.py", line 484, in _button_immediate_function
    modules.registry.Registry.new(self._cr.dbname, update_module=True)
  File "/opt/odoo/odoo/modules/registry.py", line 82, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/opt/odoo/odoo/modules/loading.py", line 339, in load_modules
    loaded_modules, update_module)
  File "/opt/odoo/odoo/modules/loading.py", line 237, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/opt/odoo/odoo/modules/loading.py", line 156, in load_module_graph
    _load_data(cr, module_name, idref, mode, kind='data')
  File "/opt/odoo/odoo/modules/loading.py", line 95, in _load_data
    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
  File "/opt/odoo/odoo/tools/convert.py", line 845, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "/opt/odoo/odoo/tools/convert.py", line 915, in convert_xml_import
    obj.parse(doc.getroot(), mode=mode)
  File "/opt/odoo/odoo/tools/convert.py", line 796, in parse
    self.parse(rec, mode)
  File "/opt/odoo/odoo/tools/convert.py", line 799, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "/opt/odoo/odoo/tools/convert.py", line 625, in _tag_record
    model = self.env[rec_model]
  File "/opt/odoo/odoo/api.py", line 760, in __getitem__
    return self.registry[model_name]._browse((), self)
  File "/opt/odoo/odoo/modules/registry.py", line 174, in __getitem__
    return self.models[model_name]
ParseError: "ir.sequence.type" while parsing /home/walid/Bureau/model_x/views/Sequences.xml:3, near
<record id="seq_type_id" model="ir.sequence.type">
        <field name="name">omega_sequence</field>
        <field name="code">hr.employee</field>
        </record>

我在我发现的所有网站上都搜索了,它们给了我一些代码,但是我一直执行这段代码,他就给我上面的错误;请给我一个建议和感谢。

1 个答案:

答案 0 :(得分:5)

版本9.0中的

ir.sequence.type模型has been removed。您可以使用以下代码:

<odoo>
    <data noupdate="1">

        <!-- ------*.xml file------- -->
        <record id="seq_hr_employee" model="ir.sequence">
            <field name="name">omega_sequencer</field>
            <field name="code">hr.employee</field>
            <field name="prefix">QO</field>
            <field name="padding">5</field>
        </record>

    </data>
</odoo>
# ------------*.py file------------------
class omega(models.Model):
    _name = 'omega.model'
    _description = 'No Description for now !!'

    sequence_id = fields.Char('Sequence', readonly=True)

    @api.model
    def create(self, vals):
        seq = self.env['ir.sequence'].next_by_code('hr.employee') or '/'
        vals['sequence_id'] = seq
        return super(omega, self).create(vals)