odoo/ext/custom-addons/dp_reports_account/models/account_invoice.py

75 lines
2.5 KiB
Python

# Copyright 2018-Today datenpol gmbh (<http://www.datenpol.at>)
# License OPL-1 or later (https://www.odoo.com/documentation/user/11.0/legal/licenses/licenses.html#licenses).
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()
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(
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 = self.mapped(
'order_line_ids.move_ids.move_line_ids.lot_id')
print('End')
@api.multi
def _compute_line_lots(self):
for line in self:
if line.prod_lot_ids:
note = u'<ul>'
note += u' '.join([
u'<li>S/N {0}</li>'.format(lot.name)
for lot in line.prod_lot_ids
])
note += u'</ul>'
line.lot_formatted_note = note