changeset 514ce8712485 in modules/account_invoice:default
details: 
https://hg.tryton.org/modules/account_invoice?cmd=changeset;node=514ce8712485
description:
        Drop foreign key for sequence

        When updating twice the same invoice, PostgreSQL takes a shared lock on 
the
        foreign key row of ir.sequence.strict. This prevent the sequence to be 
used for
        numbering during all the transaction.
        As some processes may write twice on an invoice due to modularity and 
as they
        can last too long, it is better to avoid such lock by removing the 
foreign key
        constraint. Storing the sequence id on the invoice is only to ensure 
sequential
        numbering not the integrity of the sequence record.

        issue9822
        review331161002
diffstat:

 CHANGELOG  |   1 +
 invoice.py |  14 +++++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diffs (73 lines):

diff -r eaeae8354d52 -r 514ce8712485 CHANGELOG
--- a/CHANGELOG Tue Jan 05 12:16:02 2021 +0100
+++ b/CHANGELOG Wed Jan 13 00:40:53 2021 +0100
@@ -1,3 +1,4 @@
+* Remove foreign key for sequence of Invoice
 * Add summary to invoice line list
 * Add default customer payment term configuration
 
diff -r eaeae8354d52 -r 514ce8712485 invoice.py
--- a/invoice.py        Tue Jan 05 12:16:02 2021 +0100
+++ b/invoice.py        Wed Jan 13 00:40:53 2021 +0100
@@ -94,7 +94,7 @@
         depends=['state'])
     accounting_date = fields.Date('Accounting Date', states=_states,
         depends=_depends)
-    sequence = fields.Many2One('ir.sequence.strict', "Sequence", readonly=True)
+    sequence = fields.Integer("Sequence", readonly=True)
     party = fields.Many2One('party.party', 'Party',
         required=True, states=_states, depends=_depends)
     party_tax_identifier = fields.Many2One(
@@ -378,6 +378,9 @@
                 [sql_table.state], ['cancelled'],
                 where=sql_table.state == 'cancel'))
 
+        # Migration from 5.8: drop foreign key for sequence
+        table.drop_fk('sequence')
+
     @staticmethod
     def default_type():
         return Transaction().context.get('type', 'out')
@@ -987,6 +990,7 @@
         pool = Pool()
         Date = pool.get('ir.date')
         Lang = pool.get('ir.lang')
+        Sequence = pool.get('ir.sequence.strict')
         today = Date.today()
 
         def accounting_date(invoice):
@@ -1017,7 +1021,7 @@
                 # Do not need to lock the table
                 # because sequence.get_id is sequential
                 after_invoices = cls.search([
-                            ('sequence', '=', invoice.sequence.id),
+                            ('sequence', '=', invoice.sequence),
                             ['OR',
                                 ('accounting_date', '>', date),
                                 [
@@ -1031,14 +1035,14 @@
                     raise InvoiceNumberError(
                         gettext('account_invoice.msg_invoice_number_after',
                             invoice=invoice.rec_name,
-                            sequence=invoice.sequence.rec_name,
+                            sequence=Sequence(invoice.sequence).rec_name,
                             date=Lang.get().strftime(date),
                             after_invoice=after_invoice.rec_name))
                 sequences.add(invoice.sequence)
         cls.save(invoices)
 
     def get_next_number(self, pattern=None):
-        "Return invoice number and sequence used"
+        "Return invoice number and sequence id used"
         pool = Pool()
         Sequence = pool.get('ir.sequence.strict')
         Period = pool.get('account.period')
@@ -1070,7 +1074,7 @@
                     invoice=self.rec_name,
                     fiscalyear=fiscalyear.rec_name))
         with Transaction().set_context(date=accounting_date):
-            return Sequence.get_id(sequence.id), sequence
+            return Sequence.get_id(sequence.id), sequence.id
 
     @property
     def _sequence_field(self):

Reply via email to