changeset 56e9b82a66f1 in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=56e9b82a66f1
description:
        Add delegated amount on lines to pay

        issue10345
        review346191002
diffstat:

 CHANGELOG                          |   1 +
 move.py                            |  21 +++++++++++++++++++++
 tests/scenario_move_line_group.rst |  11 +++++++++++
 view/move_line_form.xml            |   3 +++
 view/move_line_tree.xml            |   1 +
 5 files changed, 37 insertions(+), 0 deletions(-)

diffs (97 lines):

diff -r 9307e7841f70 -r 56e9b82a66f1 CHANGELOG
--- a/CHANGELOG Sun Apr 10 19:11:37 2022 +0200
+++ b/CHANGELOG Mon Apr 11 19:19:54 2022 +0200
@@ -1,3 +1,4 @@
+* Add delegated amount on move lines
 * Enforce same type for children account as their parent
 * Show debit / credit columns in ledgers when they contain lines
 * Count number of lines in Account and General Ledger
diff -r 9307e7841f70 -r 56e9b82a66f1 move.py
--- a/move.py   Sun Apr 10 19:11:37 2022 +0200
+++ b/move.py   Mon Apr 11 19:19:54 2022 +0200
@@ -841,6 +841,13 @@
         'get_amount')
     amount_currency = fields.Function(fields.Many2One('currency.currency',
             'Amount Currency'), 'get_amount_currency')
+    delegated_amount = fields.Function(Monetary(
+            "Delegated Amount",
+            currency='amount_currency', digits='amount_currency',
+            states={
+                'invisible': ~Eval('reconciliation', False),
+                }),
+        'get_delegated_amount')
 
     del _states
 
@@ -1035,6 +1042,20 @@
     order_move_origin = MoveLineMixin._order_move_field('origin')
     order_move_state = MoveLineMixin._order_move_field('state')
 
+    def get_delegated_amount(self, name):
+        def final_delegated_line(line):
+            if not line.reconciliation or not line.reconciliation.delegate_to:
+                return line
+            return final_delegated_line(line.reconciliation.delegate_to)
+
+        final_delegation = final_delegated_line(self)
+        if final_delegation == self:
+            return None
+        elif final_delegation.reconciliation:
+            return final_delegation.amount_currency.round(0)
+        else:
+            return final_delegation.amount
+
     @classmethod
     def query_get(cls, table):
         '''
diff -r 9307e7841f70 -r 56e9b82a66f1 tests/scenario_move_line_group.rst
--- a/tests/scenario_move_line_group.rst        Sun Apr 10 19:11:37 2022 +0200
+++ b/tests/scenario_move_line_group.rst        Mon Apr 11 19:19:54 2022 +0200
@@ -117,6 +117,14 @@
     >>> payable.balance, payable.amount_second_currency
     (Decimal('0.00'), Decimal('0.00'))
 
+    >>> delegated_line1, delegated_line2 = lines
+    >>> delegated_line1.reload()
+    >>> delegated_line2.reload()
+    >>> delegated_line1.delegated_amount
+    Decimal('45')
+    >>> delegated_line2.delegated_amount
+    Decimal('45')
+
     >>> Reconciliation = Model.get('account.move.reconciliation')
     >>> reconciliations = Reconciliation.find([])
     >>> len(reconciliations)
@@ -151,3 +159,6 @@
    >>> cancel.execute('cancel')
    >>> Reconciliation.find([('id', '=', reconciliations[0].id)])
    []
+
+   >>> delegated_line1.reload()
+   >>> delegated_line1.delegated_amount
diff -r 9307e7841f70 -r 56e9b82a66f1 view/move_line_form.xml
--- a/view/move_line_form.xml   Sun Apr 10 19:11:37 2022 +0200
+++ b/view/move_line_form.xml   Mon Apr 11 19:19:54 2022 +0200
@@ -34,8 +34,11 @@
             <field name="maturity_date"/>
             <label name="party"/>
             <field name="party"/>
+            <newline/>
             <label name="reconciliation"/>
             <field name="reconciliation"/>
+            <label name="delegated_amount"/>
+            <field name="delegated_amount" symbol="amount_currency"/>
             <label name="amount_second_currency"/>
             <field name="amount_second_currency"/>
             <label name="second_currency"/>
diff -r 9307e7841f70 -r 56e9b82a66f1 view/move_line_tree.xml
--- a/view/move_line_tree.xml   Sun Apr 10 19:11:37 2022 +0200
+++ b/view/move_line_tree.xml   Mon Apr 11 19:19:54 2022 +0200
@@ -11,6 +11,7 @@
     <field name="party" expand="1"/>
     <field name="debit" sum="Debit"/>
     <field name="credit" sum="Credit"/>
+    <field name="delegated_amount" optional="0"/>
     <field name="tax_lines" optional="1"/>
     <field name="description" expand="1" optional="1"/>
     <field name="move_description" expand="1" optional="1"/>

Reply via email to