mirror of
https://gitlab.com/datalifeit/trytond-ir_sequence_period
synced 2023-12-14 06:22:52 +01:00
Add prefix and suffix on period.
Allow to extend matching pattern. This commit refs #10043
This commit is contained in:
parent
721135f765
commit
a1fe785188
6 changed files with 33 additions and 9 deletions
|
@ -14,7 +14,7 @@ pipeline:
|
|||
- pip install tox
|
||||
- tox -e "${TOXENV}-${DATABASE}"
|
||||
volumes:
|
||||
- cache:/root/.cache
|
||||
- /var/lib/cache:/root/.cache
|
||||
notify:
|
||||
image: drillster/drone-email
|
||||
from: drone@datalife.com.es
|
||||
|
|
20
ir.py
20
ir.py
|
@ -56,7 +56,7 @@ class Sequence(metaclass=PoolMeta):
|
|||
if sequence.periods:
|
||||
if not date:
|
||||
cls.raise_user_error('missing_date', sequence.rec_name)
|
||||
pattern = {}
|
||||
pattern = sequence._get_period_pattern()
|
||||
for period in sequence.periods:
|
||||
if period.match(pattern):
|
||||
return period.get_id(_lock=_lock)
|
||||
|
@ -65,6 +65,9 @@ class Sequence(metaclass=PoolMeta):
|
|||
return super(Sequence, cls).get_id(domain, _lock=_lock)
|
||||
return ''
|
||||
|
||||
def _get_period_pattern(self):
|
||||
return {'date': Transaction().context.get('date')}
|
||||
|
||||
|
||||
class SequencePeriod(ModelSQL, ModelView, MatchMixin):
|
||||
'''Sequence period'''
|
||||
|
@ -84,6 +87,8 @@ class SequencePeriod(ModelSQL, ModelView, MatchMixin):
|
|||
})
|
||||
number_next = fields.Function(number_next_internal, 'get_number_next',
|
||||
'set_number_next')
|
||||
prefix = fields.Char('Prefix')
|
||||
suffix = fields.Char('Suffix')
|
||||
|
||||
@staticmethod
|
||||
def default_number_next():
|
||||
|
@ -194,9 +199,9 @@ class SequencePeriod(ModelSQL, ModelView, MatchMixin):
|
|||
cursor.execute(*query)
|
||||
date = Transaction().context.get('date')
|
||||
return '%s%s%s' % (
|
||||
Sequence._process(self.sequence.prefix, date=date),
|
||||
Sequence._process(self.prefix or self.sequence.prefix, date=date),
|
||||
self._get_sequence(),
|
||||
Sequence._process(self.sequence.suffix, date=date),
|
||||
Sequence._process(self.suffix or self.sequence.suffix, date=date),
|
||||
)
|
||||
|
||||
def _get_sequence(self):
|
||||
|
@ -218,11 +223,14 @@ class SequencePeriod(ModelSQL, ModelView, MatchMixin):
|
|||
else:
|
||||
raise NotImplementedError()
|
||||
|
||||
def match(self, pattern):
|
||||
date = Transaction().context.get('date')
|
||||
def match(self, pattern, match_none=False):
|
||||
pattern = pattern.copy()
|
||||
date = pattern.get('date')
|
||||
if not date:
|
||||
return False
|
||||
return self.start_date <= date <= self.end_date
|
||||
_match = self.start_date <= date <= self.end_date
|
||||
_ = pattern.pop('date')
|
||||
return _match and super().match(pattern, match_none=match_none)
|
||||
|
||||
|
||||
class SequenceStrict(metaclass=PoolMeta):
|
||||
|
|
|
@ -50,6 +50,14 @@ msgctxt "field:ir.sequence.period,start_date:"
|
|||
msgid "Start date"
|
||||
msgstr "Fecha inicio"
|
||||
|
||||
msgctxt "field:ir.sequence.period,prefix:"
|
||||
msgid "Prefix"
|
||||
msgstr "Prefijo"
|
||||
|
||||
msgctxt "field:ir.sequence.period,suffix:"
|
||||
msgid "Suffix"
|
||||
msgstr "Sufijo"
|
||||
|
||||
msgctxt "field:ir.sequence.period,write_date:"
|
||||
msgid "Write Date"
|
||||
msgstr "Fecha de modificación"
|
||||
|
|
|
@ -72,8 +72,10 @@ class IrSequencePeriodTestCase(ModuleTestCase):
|
|||
'sequence': sequence.id,
|
||||
'start_date': datetime.date(2019, 1, 1),
|
||||
'end_date': datetime.date(2019, 12, 31),
|
||||
'number_next': 40}])
|
||||
self.assertEqual(Sequence.get_id(sequence), '2019/40')
|
||||
'number_next': 40,
|
||||
'suffix': '/XX'
|
||||
}])
|
||||
self.assertEqual(Sequence.get_id(sequence), '2019/40/XX')
|
||||
|
||||
|
||||
def suite():
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
<field name="start_date"/>
|
||||
<label name="end_date"/>
|
||||
<field name="end_date"/>
|
||||
<label name="prefix"/>
|
||||
<field name="prefix"/>
|
||||
<label name="suffix"/>
|
||||
<field name="suffix"/>
|
||||
<label name="number_next"/>
|
||||
<field name="number_next"/>
|
||||
<label name="sequence"/>
|
||||
|
|
|
@ -5,5 +5,7 @@
|
|||
<field name="sequence"/>
|
||||
<field name="start_date"/>
|
||||
<field name="end_date"/>
|
||||
<field name="prefix"/>
|
||||
<field name="suffix"/>
|
||||
<field name="number_next"/>
|
||||
</tree>
|
Loading…
Reference in a new issue