52 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
| from odoo import api, models
 | |
| from odoo.report import report_sxw
 | |
| 
 | |
| 
 | |
| class ReportHelper(report_sxw.rml_parse):
 | |
| 
 | |
|     def __init__(self, cr, uid, name, context):
 | |
|         super(ReportHelper, self).__init__(cr, uid, name, context=context)
 | |
|         self.localcontext.update({
 | |
|             'field_set_in_lines': self._field_set_in_lines,
 | |
|             'formatLang': self._formatLang,
 | |
|         })
 | |
| 
 | |
|     @api.model
 | |
|     def _field_set_in_lines(self, lines, field):
 | |
|         fields = field.split('.')
 | |
|         for line in lines:
 | |
|             temp = None
 | |
|             for idx, field in enumerate(fields):
 | |
|                 if not temp and idx == 0:
 | |
|                     temp = line.__getattribute__(field)
 | |
|                 elif not temp and idx != 0:
 | |
|                     return False
 | |
|                 else:
 | |
|                     temp = temp.__getattribute__(field)
 | |
|             if not temp:
 | |
|                 return False
 | |
|         return True
 | |
| 
 | |
|     @api.model
 | |
|     def _formatLang(self, value, currency=True):
 | |
|         lang = self.partner_id.lang
 | |
|         lang_objs = self.env['res.lang'].search([('code', '=', lang)])
 | |
|         if not lang_objs:
 | |
|             lang_objs = self.env['res.lang'].search([], limit=1)
 | |
|         lang_obj = lang_objs[0]
 | |
| 
 | |
|         res = lang_obj.format('%.' + str(2) + 'f', value, grouping=True, monetary=True)
 | |
|         currency_obj = self.currency_id
 | |
| 
 | |
|         if currency_obj and currency_obj.symbol and currency:
 | |
|             if currency_obj.position == 'after':
 | |
|                 res = '%s %s' % (res, currency_obj.symbol)
 | |
|             elif currency_obj and currency_obj.position == 'before':
 | |
|                 res = '%s %s' % (currency_obj.symbol, res)
 | |
|         return res
 | |
| 
 | |
| 
 | |
| class AbstractReport(models.AbstractModel):
 | |
|     _inherit = 'report.abstract_report'
 | |
|     _wrapped_report_class = ReportHelper
 |