[IMP] convert: autofill sequence fields

Motivations:
* `sequence` is not super intuitive for new devs
* It makes "useless" noise in data files
* It is redundant when what we want to see in the file is the same as
  what we want to see on the user screen.
Do you understand anything related to sequences in here?
https://github.com/odoo/odoo/blob/15.0/addons/l10n_lu/data/account_tax_report_line.xml
Explicit is not always better than implicit.
* It is not implicit like using `id`  it is natural and visual and saves
  a lot of chore for adding and maintaining sequences.

Implementation
* It is optional, with the option set on root xml tags

Part-of: odoo/odoo#85750
This commit is contained in:
william
2023-10-06 13:08:51 +00:00
committed by william-andre
parent 78f6b83b34
commit b83c4fff34
2 changed files with 15 additions and 1 deletions
+1
View File
@@ -314,6 +314,7 @@
<rng:name>data</rng:name>
</rng:choice>
<rng:optional><rng:attribute name="noupdate" /></rng:optional>
<rng:optional><rng:attribute name="auto_sequence" /></rng:optional>
<rng:ref name="env"/>
<rng:zeroOrMore>
<rng:choice>
+14 -1
View File
@@ -229,7 +229,7 @@ class xml_import(object):
**safe_eval(context, {
'ref': self.id_get,
**(eval_context or {})
})
}),
}
)
return self.env
@@ -446,6 +446,10 @@ form: module.record_id""" % (xml_id,)
res[f_name] = f_val
if extra_vals:
res.update(extra_vals)
if 'sequence' not in res and 'sequence' in model._fields:
sequence = self.next_sequence()
if sequence:
res['sequence'] = sequence
data = dict(xml_id=xid, values=res, noupdate=self.noupdate)
record = model._load_records([data], self.mode == 'update')
@@ -546,6 +550,7 @@ form: module.record_id""" % (xml_id,)
self.envs.append(self.get_env(el))
self._noupdate.append(nodeattr2bool(el, 'noupdate', self.noupdate))
self._sequences.append(0 if nodeattr2bool(el, 'auto_sequence', False) else None)
try:
f(rec)
except ParseError:
@@ -568,6 +573,7 @@ form: module.record_id""" % (xml_id,)
finally:
self._noupdate.pop()
self.envs.pop()
self._sequences.pop()
@property
def env(self):
@@ -577,12 +583,19 @@ form: module.record_id""" % (xml_id,)
def noupdate(self):
return self._noupdate[-1]
def next_sequence(self):
value = self._sequences[-1]
if value is not None:
value = self._sequences[-1] = value + 10
return value
def __init__(self, env, module, idref, mode, noupdate=False, xml_filename=None):
self.mode = mode
self.module = module
self.envs = [env(context=dict(env.context, lang=None))]
self.idref = {} if idref is None else idref
self._noupdate = [noupdate]
self._sequences = []
self.xml_filename = xml_filename
self._tags = {
'record': self._tag_record,