diff --git a/account.py b/account.py index dd5f18a26e..d1da685e8b 100644 --- a/account.py +++ b/account.py @@ -8,7 +8,7 @@ from sql.conditionals import Coalesce from trytond.i18n import gettext from trytond.model import (fields, ModelView, ModelSQL, Workflow, MatchMixin, sequence_ordered) -from trytond.pyson import Eval, If, Bool +from trytond.pyson import Eval, If, Bool, Id from trytond.pool import Pool, PoolMeta from trytond.tools import grouped_slice from trytond.transaction import Transaction @@ -179,41 +179,33 @@ class InvoiceSequence(sequence_ordered(), ModelSQL, ModelView, MatchMixin): in_invoice_sequence = fields.Many2One('ir.sequence.strict', 'Supplier Invoice Sequence', required=True, domain=[ - ('code', '=', 'account.invoice'), - ['OR', - ('company', '=', Eval('company')), - ('company', '=', None), - ], + ('sequence_type', '=', + Id('account_invoice', 'sequence_type_account_invoice')), + ('company', '=', Eval('company')), ], depends=['company']) in_credit_note_sequence = fields.Many2One('ir.sequence.strict', 'Supplier Credit Note Sequence', required=True, domain=[ - ('code', '=', 'account.invoice'), - ['OR', - ('company', '=', Eval('company')), - ('company', '=', None), - ], + ('sequence_type', '=', + Id('account_invoice', 'sequence_type_account_invoice')), + ('company', '=', Eval('company')), ], depends=['company']) out_invoice_sequence = fields.Many2One('ir.sequence.strict', 'Customer Invoice Sequence', required=True, domain=[ - ('code', '=', 'account.invoice'), - ['OR', - ('company', '=', Eval('company')), - ('company', '=', None), - ], + ('sequence_type', '=', + Id('account_invoice', 'sequence_type_account_invoice')), + ('company', '=', Eval('company')), ], depends=['company']) out_credit_note_sequence = fields.Many2One('ir.sequence.strict', 'Customer Credit Note Sequence', required=True, domain=[ - ('code', '=', 'account.invoice'), - ['OR', - ('company', '=', Eval('company')), - ('company', '=', None), - ], + ('sequence_type', '=', + Id('account_invoice', 'sequence_type_account_invoice')), + ('company', '=', Eval('company')), ], depends=['company']) diff --git a/invoice.py b/invoice.py index 3cd5b4f87c..5124d0c646 100644 --- a/invoice.py +++ b/invoice.py @@ -1084,7 +1084,6 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin): def get_next_number(self, pattern=None): "Return invoice number and sequence id used" pool = Pool() - Sequence = pool.get('ir.sequence.strict') Period = pool.get('account.period') if pattern is None: @@ -1114,7 +1113,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin): invoice=self.rec_name, fiscalyear=fiscalyear.rec_name)) with Transaction().set_context(date=accounting_date): - return Sequence.get_id(sequence.id), sequence.id + return sequence.get(), sequence.id @property def _sequence_field(self): diff --git a/invoice.xml b/invoice.xml index 0484cb358b..81e04ba1a9 100644 --- a/invoice.xml +++ b/invoice.xml @@ -230,7 +230,6 @@ this repository contains the full copyright notices and license terms. --> Invoice - account.invoice diff --git a/tests/scenario_invoice.rst b/tests/scenario_invoice.rst index dcab12c817..893bac469a 100644 --- a/tests/scenario_invoice.rst +++ b/tests/scenario_invoice.rst @@ -78,7 +78,8 @@ Create payment method:: Create Write Off method:: >>> WriteOff = Model.get('account.move.reconcile.write_off') - >>> sequence_journal, = Sequence.find([('code', '=', 'account.journal')]) + >>> sequence_journal, = Sequence.find( + ... [('sequence_type.name', '=', "Account Journal")], limit=1) >>> journal_writeoff = Journal(name='Write-Off', type='write-off', ... sequence=sequence_journal) >>> journal_writeoff.save() diff --git a/tests/scenario_invoice_alternate_currency.rst b/tests/scenario_invoice_alternate_currency.rst index 4f68564604..ce9d05b6cf 100644 --- a/tests/scenario_invoice_alternate_currency.rst +++ b/tests/scenario_invoice_alternate_currency.rst @@ -80,7 +80,8 @@ Create payment method:: Create writeoff method:: >>> WriteOff = Model.get('account.move.reconcile.write_off') - >>> sequence_journal, = Sequence.find([('code', '=', 'account.journal')]) + >>> sequence_journal, = Sequence.find( + ... [('sequence_type.name', '=', "Account Journal")]) >>> journal_writeoff = Journal(name='Write-Off', type='write-off', ... sequence=sequence_journal) >>> journal_writeoff.save() diff --git a/tests/scenario_invoice_overpayment.rst b/tests/scenario_invoice_overpayment.rst index 8746b0a742..fc076de8f6 100644 --- a/tests/scenario_invoice_overpayment.rst +++ b/tests/scenario_invoice_overpayment.rst @@ -51,7 +51,8 @@ Create payment method:: Create write-off method:: >>> WriteOff = Model.get('account.move.reconcile.write_off') - >>> sequence_journal, = Sequence.find([('code', '=', 'account.journal')]) + >>> sequence_journal, = Sequence.find( + ... [('sequence_type.name', '=', "Account Journal")], limit=1) >>> journal_writeoff = Journal( ... name='Write-Off', type='write-off', sequence=sequence_journal) >>> journal_writeoff.save() diff --git a/tests/test_account_invoice.py b/tests/test_account_invoice.py index 1f2bb4af54..458d1bd870 100644 --- a/tests/test_account_invoice.py +++ b/tests/test_account_invoice.py @@ -20,9 +20,13 @@ from ..exceptions import PaymentTermValidationError def set_invoice_sequences(fiscalyear): pool = Pool() Sequence = pool.get('ir.sequence.strict') + SequenceType = pool.get('ir.sequence.type') InvoiceSequence = pool.get('account.fiscalyear.invoice_sequence') - sequence = Sequence(name=fiscalyear.name, code='account.invoice') + sequence_type, = SequenceType.search([ + ('name', '=', "Invoice"), + ], limit=1) + sequence = Sequence(name=fiscalyear.name, sequence_type=sequence_type) sequence.company = fiscalyear.company sequence.save() fiscalyear.invoice_sequences = [] diff --git a/tests/tools.py b/tests/tools.py index 903fc4528a..9a40698e70 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -8,8 +8,14 @@ __all__ = ['set_fiscalyear_invoice_sequences'] def set_fiscalyear_invoice_sequences(fiscalyear, config=None): "Set invoice sequences to fiscalyear" SequenceStrict = Model.get('ir.sequence.strict', config=config) + SequenceType = Model.get('ir.sequence.type', config=config) - invoice_seq = SequenceStrict(name=fiscalyear.name, code='account.invoice', + sequence_type, = SequenceType.find([ + ('name', '=', "Invoice"), + ], limit=1) + invoice_seq = SequenceStrict( + name=fiscalyear.name, + sequence_type=sequence_type, company=fiscalyear.company) invoice_seq.save() seq, = fiscalyear.invoice_sequences