From c2189b8e4a429ae2a8379882cf80504af3b7bf2b Mon Sep 17 00:00:00 2001
From: Benjamin <benjamin@le-filament.com>
Date: Thu, 1 Apr 2021 19:32:17 +0200
Subject: [PATCH] [add] date_maturity on account_payment widget

---
 __manifest__.py                    |  3 +++
 models/account_invoice.py          | 36 ++++++++++++++++++++++++++++++
 static/src/xml/account_payment.xml | 17 ++++++++++++++
 3 files changed, 56 insertions(+)
 create mode 100644 static/src/xml/account_payment.xml

diff --git a/__manifest__.py b/__manifest__.py
index d026b4c..06892d8 100755
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -24,5 +24,8 @@
         "views/res_partner.xml",
         "views/scop_cotisation_task.xml",
     ],
+    "qweb": [
+        "static/src/xml/*.xml",
+    ],
     'post_init_hook': '_configure_journals',
 }
diff --git a/models/account_invoice.py b/models/account_invoice.py
index 86d2d2b..263076c 100755
--- a/models/account_invoice.py
+++ b/models/account_invoice.py
@@ -1,6 +1,9 @@
 # © 2020 Le Filament (<http://www.le-filament.com>)
 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
 
+from datetime import datetime
+import json
+
 from odoo import models, fields, api, _
 from odoo.exceptions import UserError
 
@@ -207,6 +210,39 @@ class ScopAccountInvoice(models.Model):
             inv.write(vals)
         return True
 
+    @api.one
+    def _get_outstanding_info_JSON(self):
+        super(ScopAccountInvoice, self)._get_outstanding_info_JSON()
+        info = json.loads(self.outstanding_credits_debits_widget)
+        if info:
+            values = info.get('content', False)
+            if self.state == 'open' and values:
+                domain = [('account_id', '=', self.account_id.id),
+                          ('partner_id', '=',
+                           self.env['res.partner']._find_accounting_partner(
+                               self.partner_id).id),
+                          ('reconciled', '=', False),
+                          ('move_id.state', '=', 'posted'),
+                          '|',
+                          '&', ('amount_residual_currency', '!=', 0.0),
+                          ('currency_id', '!=', None),
+                          '&', ('amount_residual_currency', '=', 0.0), '&',
+                          ('currency_id', '=', None),
+                          ('amount_residual', '!=', 0.0)]
+                if self.type in ('out_invoice', 'in_refund'):
+                    domain.extend([('credit', '>', 0), ('debit', '=', 0)])
+                else:
+                    domain.extend([('credit', '=', 0), ('debit', '>', 0)])
+                lines = self.env['account.move.line'].search(domain)
+                for value in values:
+                    for line in lines:
+                        if value.get('id') == line.id:
+                            value.update({
+                                'date_maturity': datetime.strftime(line.date_maturity, "%d/%m/%Y"),
+                                'invoice': line.invoice_id.number
+                            })
+                self.outstanding_credits_debits_widget = json.dumps(info)
+
     # ------------------------------------------------------
     # Common Function
     # ------------------------------------------------------
diff --git a/static/src/xml/account_payment.xml b/static/src/xml/account_payment.xml
new file mode 100644
index 0000000..5cc4c24
--- /dev/null
+++ b/static/src/xml/account_payment.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<templates xml:space="preserve">
+
+    <!--  Copyright 2020 Le Filament
+          License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).  -->
+
+    <t t-extend="ShowPaymentInfo">
+        <t t-jquery='div.oe_form_field' t-operation='replace'>
+            <div class="oe_form_field"
+                 style="margin-right: 10px; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;"
+                 t-att-title="line.date_maturity + ' - ' + line.title">
+                <t t-esc="line.date_maturity"></t> - <t t-esc="line.invoice"></t>
+            </div>
+        </t>
+    </t>
+
+</templates>
\ No newline at end of file
-- 
GitLab