From 904bf6c4f4c0e22faccf033f91a9db7e59ab4a8b Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 19 Nov 2018 10:52:04 +0100 Subject: [PATCH] Cut name_get() of invoice if too long (which screws-up the invoice form view because of the ariane thread at the top) --- account_usability/account.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/account_usability/account.py b/account_usability/account.py index 75b7417..88af82a 100644 --- a/account_usability/account.py +++ b/account_usability/account.py @@ -43,7 +43,6 @@ class AccountInvoice(models.Model): compute='_compute_has_attachment', search='_search_has_attachment', readonly=True) - @api.multi def _compute_has_discount(self): prec = self.env['decimal.precision'].precision_get('Discount') for inv in self: @@ -78,6 +77,25 @@ class AccountInvoice(models.Model): res = [('id', value and 'in' or 'not in', att_inv_ids.keys())] return res + # when you have an invoice created from a lot of sale orders, the 'name' + # field is very large, which makes the name_get() of that invoice very big + # which screws-up the form view of that invoice because of the link at the + # top of the screen + # That's why we have to cut the name_get() when it's too long + def name_get(self): + old_res = super(AccountInvoice, self).name_get() + res = [] + for old_re in old_res: + name = old_re[1] + if name and len(name) > 100: + # nice cut + name = u'%s ...' % ', '.join(name.split(', ')[:3]) + # if not enough, hard cut + if len(name) > 120: + name = u'%s ...' old_re[1][:120] + res.append((old_re[0], name)) + return res + # I really hate to see a "/" in the 'name' field of the account.move.line # generated from customer invoices linked to the partners' account because: # 1) the label of an account move line is an important field, we can't