# Copyright 2018-Today datenpol gmbh () # License OPL-1 or later (https://www.odoo.com/documentation/user/11.0/legal/licenses/licenses.html#licenses). from itertools import groupby from odoo import api, fields, models class AccountInvoice(models.Model): _inherit = 'account.invoice' @api.multi def order_lines_layouted(self): # res = super(AccountInvoice, self).order_lines_layouted() self.ensure_one() res = [[]] for category, lines in groupby(self.invoice_line_ids.sorted(key=lambda s: s.layout_category_id.name or ''), lambda l: l.layout_category_id): # If last added category induced a pagebreak, this one will be on a new page if res[-1] and res[-1][-1]['pagebreak']: res.append([]) # Append category to current report page res[-1].append({ 'name': category and category.name or 'Uncategorized', 'subtotal': category and category.subtotal, 'pagebreak': category and category.pagebreak, 'lines': list(lines) }) uncategorized = False # Rechnungszeilen ohne Kategorie löschen und an den Anfang stellen for idx1, page in enumerate(res): for idx2, category in enumerate(page): if category.get('name') == 'Uncategorized': uncategorized = page.pop(idx2) if uncategorized: res[idx1] = [uncategorized] + res[idx1] for page in res: for category in page: price_subtotal = 0.0 for line in category['lines']: price_subtotal += line.price_subtotal category['price_subtotal'] = price_subtotal sale_order = self.env['sale.order'].search([('name', '=', category['name'])]) if sale_order: category['order_id'] = sale_order return res class AccountInvoiceLine(models.Model): _inherit = "account.invoice.line" order_line_ids = fields.Many2many( comodel_name='sale.order.line', relation='sale_order_line_invoice_rel', column1='invoice_line_id', column2='order_line_id', string='Order Lines', readonly=True, ) prod_lot_ids = fields.Many2many( comodel_name='stock.production.lot', compute='_compute_prod_lots', string="Production Lots", ) lot_formatted_note = fields.Html( comodel_name='stock.production.lot', string='Formatted Note', compute='_compute_line_lots', ) @api.multi def _compute_prod_lots(self): for line in self: if not line.order_line_ids: return line.prod_lot_ids = line.mapped( 'order_line_ids.move_ids.move_line_ids.lot_id') @api.multi def _compute_line_lots(self): for line in self: if line.prod_lot_ids: note = u'' line.lot_formatted_note = note