[FIX] repair: fix html formatting in narration

Followup of odoo/odoo@cb4f597410 and odoo/enterprise@971f3ed9ae

We have converted string into markup string in repair as we cannot concatenate
strings directly to Markup string. And if we try to do it we will see the
html elements '<br/>' in field value, so we have to convert '<br/>' string
into markup language to avoid this.

Also avoid adding pseudo-void html content in narration.

LINKS

Task Id-2558824
PR odoo/odoo#74795
PR odoo/enterprise#20117
This commit is contained in:
dht-odoo
2021-08-18 08:22:20 +00:00
committed by Thibault Delavallée
parent 53cc41016f
commit 48a591c409
+9 -6
View File
@@ -3,9 +3,11 @@
from collections import defaultdict
from random import randint
from markupsafe import Markup
from odoo import api, fields, models, _
from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_compare
from odoo.tools import float_compare, is_html_empty
class StockMove(models.Model):
@@ -344,7 +346,7 @@ class Repair(models.Model):
'partner_id': partner_invoice.id,
'partner_shipping_id': repair.address_id.id,
'currency_id': currency.id,
'narration': narration,
'narration': narration if not is_html_empty(narration) else '',
'invoice_origin': repair.name,
'repair_ids': [(4, repair.id)],
'invoice_line_ids': [],
@@ -358,10 +360,11 @@ class Repair(models.Model):
invoice_vals = current_invoices_list[0]
invoice_vals['invoice_origin'] += ', ' + repair.name
invoice_vals['repair_ids'].append((4, repair.id))
if not invoice_vals['narration']:
invoice_vals['narration'] = narration
else:
invoice_vals['narration'] += '<br/>' + narration
if not is_html_empty(narration):
if is_html_empty(invoice_vals['narration']):
invoice_vals['narration'] = narration
else:
invoice_vals['narration'] += Markup('<br/>') + narration
# Create invoice lines from operations.
for operation in repair.operations.filtered(lambda op: op.type == 'add'):