Sergi Almacellas Abellana pushed to branch branch/default at Tryton / Tryton


Commits:
4955ce2c by Sergi Almacellas Abellana at 2023-06-22T16:11:33+00:00
Allow modification of invoice references when report is not cached
- - - - -


3 changed files:

- modules/account_invoice/CHANGELOG
- modules/account_invoice/invoice.py
- modules/account_invoice/tests/scenario_invoice.rst


Changes:

=====================================
modules/account_invoice/CHANGELOG
=====================================
@@ -1,3 +1,4 @@
+* Allow modification of invoice references when report is not cached
 * Add cache on invoice's amounts
 
 Version 6.8.0 - 2023-05-01


=====================================
modules/account_invoice/invoice.py
=====================================
@@ -80,7 +80,11 @@
             })
     type_name = fields.Function(fields.Char('Type'), 'get_type_name')
     number = fields.Char("Number", readonly=True)
-    reference = fields.Char('Reference', size=None, states=_states)
+    reference = fields.Char(
+        "Reference",
+        states={
+            'readonly': Eval('has_report_cache', False),
+        })
     description = fields.Char('Description', size=None, states=_states)
     state = fields.Selection([
             ('draft', "Draft"),
@@ -290,6 +294,8 @@
         fields.Boolean("Allow Cancel Invoice"), 'get_allow_cancel')
     has_payment_method = fields.Function(
         fields.Boolean("Has Payment Method"), 'get_has_payment_method')
+    has_report_cache = fields.Function(
+        fields.Boolean("Has Report Cached"), 'get_has_report_cache')
 
     del _states
 
@@ -329,7 +335,7 @@
             'move', 'cancel_move', 'additional_moves',
             'invoice_report_cache', 'invoice_report_format',
             'total_amount_cache', 'tax_amount_cache', 'untaxed_amount_cache',
-            'lines'}
+            'lines', 'reference'}
         cls._order = [
             ('number', 'DESC NULLS FIRST'),
             ('id', 'DESC'),
@@ -932,6 +938,22 @@
             methods.update(dict.fromkeys(sub_invoice_ids, value))
         return methods
 
+    @classmethod
+    def get_has_report_cache(cls, invoices, name):
+        table = cls.__table__()
+        cursor = Transaction().connection.cursor()
+
+        result = {}
+        has_cache = (
+            (table.invoice_report_cache_id != Null)
+            | (table.invoice_report_cache != Null))
+        for sub_invoices in grouped_slice(invoices):
+            sub_ids = map(int, sub_invoices)
+            cursor.execute(*table.select(table.id, has_cache,
+                    where=reduce_ids(table.id, sub_ids)))
+            result.update(cursor)
+        return result
+
     @property
     def taxable_lines(self):
         taxable_lines = []


=====================================
modules/account_invoice/tests/scenario_invoice.rst
=====================================
@@ -156,6 +156,8 @@
     >>> invoice.total_amount
     Decimal('240.00')
     >>> invoice.save()
+    >>> bool(invoice.has_report_cache)
+    False
 
 Test change tax::
 
@@ -173,6 +175,8 @@
     'posted'
     >>> invoice.tax_identifier.code
     'BE0897290877'
+    >>> bool(invoice.has_report_cache)
+    True
     >>> invoice.untaxed_amount
     Decimal('220.00')
     >>> invoice.tax_amount



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/4955ce2c71407d3e6dd4207c2d1f9130b4dd0b9b

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/4955ce2c71407d3e6dd4207c2d1f9130b4dd0b9b
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to