How can I create a strict sequence from the XML?

I’m trying to create an XML to set up a strict sequence in ir.sequence.strict, but it’s not working. It generates an error when I execute ‘tryto-admin -c conf -d database --all’. However, when it’s a sequence in ir.sequence, it generates without any issue, I just change the reference to the model.

<?xml version="1.0" encoding="utf-8"?>
<tryton>
    <data>
<!-- Sequences for invoice -->
        <record id="seq_type_invoice_order" model="ir.sequence.type">
            <field name="name">order invoice</field>
        </record>
        <record id="seq_invoice_order" model="ir.sequence.strict">
            <field name="name">order invo</field>
            <field name="sequence_type" ref="seq_type_invoice_order" ></field>
            <field name="padding">0</field>
            <field name="company" eval="1"/>
			<field name="number_increment"  eval="1"/>

        </record>
</data>
    <data noupdate="1">
        <record model="invoice.sequences.invoice_sequence"
            id="invoice_sequences">
            <field name="invoice_sequence" ref="seq_invoice_order"/>
        </record>
    </data>
</tryton>

thank you

What is exactly the error?

C(tryton) root@localhost:~# tryto-admin -c /opt/tryton/config/trytond.conf -d tryton --all
Traceback (most recent call last):
  File "/opt/tryton/lib64/python3.11/site-packages/trytond/convert.py", line 464, in parse_xmlstream
    self.sax_parser.parse(source)
  File "/usr/lib64/python3.11/xml/sax/expatreader.py", line 111, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib64/python3.11/xml/sax/xmlreader.py", line 125, in parse
    self.feed(buffer)
  File "/usr/lib64/python3.11/xml/sax/expatreader.py", line 217, in feed
    self._parser.Parse(data, isFinal)
  File "/builddir/build/BUILD/Python-3.11.7/Modules/pyexpat.c", line 468, in EndElement
  File "/usr/lib64/python3.11/xml/sax/expatreader.py", line 336, in end_element
    self._cont_handler.endElement(name)
  File "/opt/tryton/lib64/python3.11/site-packages/trytond/convert.py", line 519, in endElement
    self.taghandler = self.taghandler.endElement(name)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/tryton/lib64/python3.11/site-packages/trytond/convert.py", line 314, in endElement
    self.mh.import_record(
  File "/opt/tryton/lib64/python3.11/site-packages/trytond/convert.py", line 627, in import_record
    raise ParsingError(
trytond.convert.ParsingError: wrong model 'ir.sequence.strict': account_es_es_vf.seq_invoice_order

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/tryton/bin/trytond-admin", line 31, in <module>
    admin.run(options)
  File "/opt/tryton/lib64/python3.11/site-packages/trytond/admin.py", line 57, in run
    pool.init(update=options.update, lang=list(lang),
  File "/opt/tryton/lib64/python3.11/site-packages/trytond/pool.py", line 167, in init
    restart = not load_modules(
                  ^^^^^^^^^^^^^
  File "/opt/tryton/lib64/python3.11/site-packages/trytond/modules/__init__.py", line 384, in load_modules
    _load_modules(update)
  File "/opt/tryton/lib64/python3.11/site-packages/trytond/modules/__init__.py", line 352, in _load_modules
    load_module_graph(graph, pool, update, lang)
  File "/opt/tryton/lib64/python3.11/site-packages/trytond/modules/__init__.py", line 203, in load_module_graph
    tryton_parser.parse_xmlstream(fp)
  File "/opt/tryton/lib64/python3.11/site-packages/trytond/convert.py", line 466, in parse_xmlstream
    raise ParsingError("in %s" % self.current_state()) from e
trytond.convert.ParsingError: in record 'account_es_es_vf.seq_invoice_order'

It is just that your field invoice_sequence is not a Many2One to ir.sequence.strict.

However, if I only use ‘ir.sequence’, the code works and generates the fields in non-strict sequences.

from trytond.pool import Pool
from trytond.pool import PoolMeta
from trytond.model import (ModelView, ModelSingleton, ModelSQL, ValueMixin, MultiValueMixin, fields)
from trytond.pyson import Id

invoice_sequence = fields.Many2One(
    'ir.sequence.strict', 'invoice order', required=True,
    domain=[('sequence_type', '=', Id(
        'account_es_es_vf', 'seq_type_invoice_order'))])
class InvoiceSequences(ModelSingleton, ModelSQL, ModelView, MultiValueMixin):
    'Invoice Sequences'
    __name__ = 'invoice.sequences'

    invoice_sequence = fields.MultiValue(invoice_sequence)

    @classmethod
    def default_invoice_sequence(cls, **pattern):
        pool = Pool()
        ModelData = pool.get('ir.model.data')
        try:
            return ModelData.get_id('account_es_es_vf', 'seq_invoice_order')
        except KeyError:
            return None

class ConfigurationSequence(ModelSQL, ValueMixin):
    'invoice Configuration Sequence'
    __name__ = 'invoice.sequences.invoice_sequence'
    invoice_sequence= invoice_sequence

    @classmethod
    def check_xml_record(cls, records, values):
        return True

Indeed you just pollute your database by changing the model of the XML record without changing the ID.

Thanks, but I also changed the ID in the XML. I’ll try with a new empty database; it’s the only thing I haven’t tried yet. Thanks

Thank you very much. If it’s a database poisoning/contamination issue, it works in the previous state of the database.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.