1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Author: Lorenzo Battistini <lorenzo.battistini@agilebg.com>
6
# Copyright (C) 2011 Domsense s.r.l. (<http://www.domsense.com>).
7
# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as
11
# published by the Free Software Foundation, either version 3 of the
12
# License, or (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
24
from openerp.osv import fields, orm
27
class account_invoice_line(orm.Model):
29
def _get_prod_lots(self, cr, uid, ids, field_name, arg, context=None):
31
for line in self.browse(cr, uid, ids, context=context):
33
for order_line in line.order_lines:
34
for move in order_line.move_ids:
36
result[line.id].append(move.prodlot_id.id)
39
_inherit = "account.invoice.line"
42
# order_lines is the reverse of invoice_lines field of sale module
43
'order_lines': fields.many2many(
44
'sale.order.line', 'sale_order_line_invoice_rel', 'invoice_id',
45
'order_line_id', 'Order Lines', readonly=True),
46
'prod_lot_ids': fields.function(
47
_get_prod_lots, method=True, type='many2many',
48
relation="stock.production.lot", string="Production Lots"),
49
'displayed_lot_id': fields.many2one('stock.production.lot', 'Lot'),
52
def load_line_lots(self, cr, uid, ids, context=None):
53
for line in self.browse(cr, uid, ids, context):
57
u'<li>S/N {0}</li>'.format(lot.name)
58
for lot in line.prod_lot_ids
61
line.write({'formatted_note': note}, context=context)
64
def create(self, cr, uid, vals, context=None):
65
res = super(account_invoice_line, self).create(cr, uid, vals, context)
66
if not vals.get('formatted_note'):
67
self.load_line_lots(cr, uid, [res], context)
70
class account_invoice(orm.Model):
72
def load_lines_lots(self, cr, uid, ids, context=None):
73
invoices = self.browse(cr, uid, ids, context)
74
inv_line_obj = self.pool.get('account.invoice.line')
75
for invoice in invoices:
76
inv_line_obj.load_line_lots(cr, uid, [l.id for l in invoice.invoice_line], context)
79
_inherit = "account.invoice"