diff --git a/account_usability/account.py b/account_usability/account.py index a5faf07..82d539c 100644 --- a/account_usability/account.py +++ b/account_usability/account.py @@ -6,6 +6,7 @@ from odoo import models, fields, api, _ from odoo.tools import float_compare, float_is_zero from odoo.exceptions import UserError +from itertools import groupby class AccountInvoice(models.Model): @@ -56,6 +57,48 @@ class AccountInvoice(models.Model): # return res + # for report + @api.multi + def py3o_lines_layout(self): + self.ensure_one() + res1 = [] + # [ + # {'categ': categ(6), 'lines': [l1, l2], 'subtotal': 23.32}, + # {'categ': categ(1), 'lines': [l3, l4, l5], 'subtotal': 12.42}, + # ] + for categ, lines in\ + groupby(self.invoice_line_ids, lambda l: l.layout_category_id): + entry = {'lines': [], 'categ': categ} + if categ.subtotal: + entry['subtotal'] = 0.0 + for line in lines: + entry['lines'].append(line) + if 'subtotal' in entry: + entry['subtotal'] += line.price_subtotal + res1.append(entry) + res2 = [] + if len(res1) == 1 and not res1[0]['categ']: + # No category at all + for l in res1[0]['lines']: + res2.append({'line': l}) + else: + # TODO : gérer qd il n'y a pas de categ + for ldict in res1: + res2.append({'categ': ldict['categ']}) + for line in ldict['lines']: + res2.append({'line': line}) + if 'subtotal' in ldict: + res2.append({'subtotal': ldict['subtotal']}) + # res2: + # [ + # {'categ': categ(1)}, + # {'line': invoice_line(2)}, + # {'line': invoice_line(3)}, + # {'subtotal': 8932.23}, + # ] + return res2 + + class AccountInvoiceLine(models.Model): _inherit = 'account.invoice.line' diff --git a/base_usability/__init__.py b/base_usability/__init__.py index 32f4452..767083b 100644 --- a/base_usability/__init__.py +++ b/base_usability/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from . import partner +from . import company from . import mail from . import misc from . import report_sxw diff --git a/base_usability/company.py b/base_usability/company.py new file mode 100644 index 0000000..2cb4206 --- /dev/null +++ b/base_usability/company.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# © 2015-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api, _ + + +class ResCompany(models.Model): + _inherit = 'res.company' + + @api.model + def generate_line(self, fields, options, icon=True, separator=' - '): + assert fields + assert options + content = [] + for field in fields: + value = False + if isinstance(field, tuple) and len(field) == 2: + value = field[0] + label = field[1] + uicon = False + elif isinstance(field, (str, unicode)) and field in options: + value = options[field]['value'] + label = options[field].get('label') + uicon = options[field].get('icon') + if value: + prefix = icon and uicon or label + if prefix: + content.append(u'%s %s' % (prefix, value)) + else: + content.append(value) + line = separator.join(content) + return line + + @api.multi + def _prepare_header_options(self): + self.ensure_one() + options = { + 'phone': { + 'value': self.phone, + # http://www.fileformat.info/info/unicode/char/1f4de/index.htm + 'icon': u'\U0001F4DE', + 'label': _('Tel:')}, + 'fax': { + 'value': self.fax, + # http://www.fileformat.info/info/unicode/char/1f5b7/index.htm + 'icon': u'\U0001F5B7', + 'label': _('Fax:')}, + 'email': { + 'value': self.email, + # http://www.fileformat.info/info/unicode/char/2709/index.htm + 'icon': u'\u2709', + 'label': _('E-mail:')}, + 'website': { + 'value': self.website, + 'icon': u'\U0001f310', + 'label': _('Website:')}, + 'vat': { + 'value': self.vat, + 'label': _('TVA :')}, # TODO translate + } + return options + + # for reports + @api.multi + def _display_report_header( + self, line_details=[['phone', 'fax', 'website'], ['vat']], + icon=True, line_separator=' - '): + self.ensure_one() + res = u'' + address = self.partner_id._display_address(without_company=True) + address = address.replace('\n', u' - ') + line1 = u'%s - %s' % (self.name, address) + lines = [line1] + options = self._prepare_header_options() + for details in line_details: + line = self.generate_line( + details, options, icon=icon, separator=line_separator) + lines.append(line) + res = '\n'.join(lines) + return res diff --git a/sale_usability/sale.py b/sale_usability/sale.py index e2c5e02..65315aa 100644 --- a/sale_usability/sale.py +++ b/sale_usability/sale.py @@ -43,7 +43,8 @@ class SaleOrder(models.Model): # {'categ': categ(6), 'lines': [l1, l2], 'subtotal': 23.32}, # {'categ': categ(1), 'lines': [l3, l4, l5], 'subtotal': 12.42}, # ] - for categ, lines in groupby(self.order_line, lambda l: l.layout_category_id): + for categ, lines in\ + groupby(self.order_line, lambda l: l.layout_category_id): entry = {'lines': [], 'categ': categ} if categ.subtotal: entry['subtotal'] = 0.0 @@ -61,8 +62,8 @@ class SaleOrder(models.Model): # TODO : gérer qd il n'y a pas de categ for ldict in res1: res2.append({'categ': ldict['categ']}) - for soline in ldict['lines']: - res2.append({'line': soline}) + for line in ldict['lines']: + res2.append({'line': line}) if 'subtotal' in ldict: res2.append({'subtotal': ldict['subtotal']}) # res2: