[IMP] account: improve the payment terms preview

This commit improves the payment terms by:
- Showing "Payment terms" instead of "Due date" if the user has selected payment terms (instead of a due date)
- Auto-fill the amount and date example in the dynamic preview of the payment terms if the user opens the payments terms popup.

closes odoo/odoo#101488

X-original-commit: 04c1f169e5e97a7f92bdf009ed545eb8607f943b
Signed-off-by: Quentin De Paoli <qdp@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
Ricardo Gomes Rodrigues (rigr)
2022-09-28 19:31:56 +02:00
parent d666f57079
commit 5026b6806d
2 changed files with 16 additions and 4 deletions
@@ -15,6 +15,12 @@ class AccountPaymentTerm(models.Model):
def _default_line_ids(self):
return [Command.create({'value': 'balance', 'value_amount': 0.0, 'days': 0, 'end_month': False})]
def _default_example_amount(self):
return self._context.get('example_amount') or 100 # Force default value if the context is set to False
def _default_example_date(self):
return self._context.get('example_date') or fields.Date.today()
name = fields.Char(string='Payment Terms', translate=True, required=True)
active = fields.Boolean(default=True, help="If the active field is set to False, it will allow you to hide the payment terms without removing it.")
note = fields.Html(string='Description on the Invoice', translate=True)
@@ -22,8 +28,8 @@ class AccountPaymentTerm(models.Model):
company_id = fields.Many2one('res.company', string='Company')
sequence = fields.Integer(required=True, default=10)
display_on_invoice = fields.Boolean(string='Display terms on invoice', help="If set, the payment deadlines and respective due amounts will be detailed on invoices.")
example_amount = fields.Float(default=100, store=False)
example_date = fields.Date(string='Date example', default=fields.Date.context_today, store=False)
example_amount = fields.Float(default=_default_example_amount, store=False)
example_date = fields.Date(string='Date example', default=_default_example_date, store=False)
example_invalid = fields.Boolean(compute='_compute_example_invalid')
example_preview = fields.Html(compute='_compute_example_preview')
@@ -213,6 +219,7 @@ class AccountPaymentTermLine(models.Model):
payment_id = fields.Many2one('account.payment.term', string='Payment Terms', required=True, index=True, ondelete='cascade')
def _get_due_date(self, date_ref):
self.ensure_one()
due_date = fields.Date.from_string(date_ref)
due_date += relativedelta(months=self.months)
due_date += relativedelta(days=self.days)
+7 -2
View File
@@ -813,8 +813,12 @@
attrs="{'invisible': [('move_type', 'not in', ('in_invoice', 'in_refund', 'in_receipt'))]}"/>
<!-- Invoice payment terms (only invoices) + due date (only invoices / receipts) -->
<label for="invoice_payment_term_id" string="Due Date"
attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}"/>
<div class="o_td_label" attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}">
<label for="invoice_payment_term_id" string="Due Date"
attrs="{'invisible': [('invoice_payment_term_id', '!=', False)]}"/>
<label for="invoice_payment_term_id" string="Payment terms"
attrs="{'invisible': [('invoice_payment_term_id', '=', False)]}"/>
</div>
<div class="d-flex" attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}">
<field name="invoice_date_due" force_save="1"
placeholder="Date"
@@ -822,6 +826,7 @@
<span class="o_form_label mx-3 oe_edit_only"
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('invoice_payment_term_id', '!=', False)]}"> or </span>
<field name="invoice_payment_term_id"
context="{'example_date': invoice_date, 'example_amount': tax_totals['amount_total']}"
placeholder="Terms"/>
</div>