diff --git a/account_usability/account.py b/account_usability/account.py index c23564b..6d17a11 100644 --- a/account_usability/account.py +++ b/account_usability/account.py @@ -140,6 +140,36 @@ class AccountInvoice(models.Model): attach.id, attach.name) logger.info('END fix customer invoice attachment filename') + # for report + def py3o_lines_layout(self): + self.ensure_one() + res = [] + has_sections = False + subtotal = 0.0 + sign = self.type == 'out_refund' and -1 or 1 + for line in self.invoice_line_ids: + if line.display_type == 'line_section': + # insert line + if has_sections: + res.append({'subtotal': subtotal}) + subtotal = 0.0 # reset counter + has_sections = True + else: + if not line.display_type: + subtotal += line.price_subtotal * sign + res.append({'line': line}) + if has_sections: # insert last subtotal line + res.append({'subtotal': subtotal}) + # res: + # [ + # {'line': account_invoice_line(1) with display_type=='line_section'}, + # {'line': account_invoice_line(2) without display_type}, + # {'line': account_invoice_line(3) without display_type}, + # {'line': account_invoice_line(4) with display_type=='line_note'}, + # {'subtotal': 8932.23}, + # ] + return res + class AccountInvoiceLine(models.Model): _inherit = 'account.invoice.line' diff --git a/purchase_usability/purchase.py b/purchase_usability/purchase.py index 6676eea..ac42171 100644 --- a/purchase_usability/purchase.py +++ b/purchase_usability/purchase.py @@ -28,8 +28,8 @@ class PurchaseOrder(models.Model): order.delivery_partner_id = order.dest_address_id def print_order(self): - action = self.env['report'].get_action( - self, 'purchase.report_purchaseorder') + report = self.env.ref('purchase.action_report_purchase_order') + action = report.report_action(self) return action # Re-write native name_get() to use amount_untaxed instead of amount_total diff --git a/sale_usability/account_invoice.py b/sale_usability/account_invoice.py index a7d7acc..8b8316c 100644 --- a/sale_usability/account_invoice.py +++ b/sale_usability/account_invoice.py @@ -10,44 +10,6 @@ from collections import OrderedDict class AccountInvoice(models.Model): _inherit = 'account.invoice' - # for report (located in sale_usability and not account_usability - # because it uses layout categ defined in sale - # Method used in the sample invoice report available here: - # https://github.com/akretion/odoo-py3o-report-templates/tree/10.0/account_invoice_report_py3o - def py3o_lines_layout(self): - self.ensure_one() - res1 = OrderedDict() - # {'categ(6)': {'lines': [l1, l2], 'subtotal': 23.32}} - for line in self.invoice_line_ids: - categ = line.layout_category_id - if categ in res1: - res1[categ]['lines'].append(line) - res1[categ]['subtotal'] += line.price_subtotal - else: - res1[categ] = { - 'lines': [line], - 'subtotal': line.price_subtotal} - res2 = [] - if len(res1) == 1 and not res1.keys()[0]: - # No category at all - for line in res1.values()[0]['lines']: - res2.append({'line': line}) - else: - for categ, ldict in res1.iteritems(): - res2.append({'categ': categ}) - for line in ldict['lines']: - res2.append({'line': line}) - if categ.subtotal: - res2.append({'subtotal': ldict['subtotal']}) - # res2: - # [ - # {'categ': categ(1)}, - # {'line': invoice_line(2)}, - # {'line': invoice_line(3)}, - # {'subtotal': 8932.23}, - # ] - return res2 - def py3o_lines_layout_groupby_order(self, subtotal=True): # This method is an alternative to the method py3o_lines_layout() # defined above: you just have to change the call in the invoice