changeset af10119a0c2a in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=af10119a0c2a
description:
        Use company of the move created to retrieve the numbering sequence

        issue10634
        review342831004
diffstat:

 move.py |  18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diffs (33 lines):

diff -r 0fdc813deaa2 -r af10119a0c2a move.py
--- a/move.py   Sat Jul 24 09:42:06 2021 +0200
+++ b/move.py   Mon Aug 16 23:08:50 2021 +0200
@@ -270,16 +270,24 @@
     def create(cls, vlist):
         pool = Pool()
         Journal = pool.get('account.journal')
+        context = Transaction().context
 
+        journals = {}
+        default_company = cls.default_company()
         vlist = [x.copy() for x in vlist]
         for vals in vlist:
             if not vals.get('number'):
-                journal_id = (vals.get('journal')
-                        or Transaction().context.get('journal'))
+                journal_id = vals.get('journal', context.get('journal'))
+                company_id = vals.get('company', default_company)
                 if journal_id:
-                    journal = Journal(journal_id)
-                    if journal.sequence:
-                        vals['number'] = journal.sequence.get()
+                    if journal_id not in journals:
+                        journal = journals[journal_id] = Journal(journal_id)
+                    else:
+                        journal = journals[journal_id]
+                    sequence = journal.get_multivalue(
+                        'sequence', company=company_id)
+                    if sequence:
+                        vals['number'] = sequence.get()
 
         moves = super(Move, cls).create(vlist)
         cls.validate_move(moves)

Reply via email to