1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 from osv import osv, fields
25 class stock_move(osv.osv):
26 _inherit = 'stock.move'
28 'purchase_line_id': fields.many2one('purchase.order.line',
29 'Purchase Order Line', ondelete='set null', select=True,
33 'purchase_line_id': lambda *a:False
38 # Inherit of picking to add the link to the PO
40 class stock_picking(osv.osv):
41 _inherit = 'stock.picking'
43 'purchase_id': fields.many2one('purchase.order', 'Purchase Order',
44 ondelete='set null', select=True, readonly=True),
47 'purchase_id': lambda *a: False,
50 def _get_comment_invoice(self, cursor, user, picking):
51 if picking.purchase_id and picking.purchase_id.notes:
53 return picking.note + '\n' + picking.purchase_id.notes
55 return picking.purchase_id.notes
56 return super(stock_picking, self)._get_comment_invoice(cursor, user,
59 def _get_price_unit_invoice(self, cursor, user, move_line, type):
60 if move_line.purchase_line_id:
61 return move_line.purchase_line_id.price_unit
62 return super(stock_picking, self)._get_price_unit_invoice(cursor,
63 user, move_line, type)
65 def _get_discount_invoice(self, cursor, user, move_line):
66 if move_line.purchase_line_id:
68 return super(stock_picking, self)._get_discount_invoice(cursor, user,
71 def _get_taxes_invoice(self, cursor, user, move_line, type):
72 if move_line.purchase_line_id:
73 return [x.id for x in move_line.purchase_line_id.taxes_id]
74 return super(stock_picking, self)._get_taxes_invoice(cursor, user,
77 def _get_account_analytic_invoice(self, cursor, user, picking, move_line):
78 if move_line.purchase_line_id:
79 return move_line.purchase_line_id.account_analytic_id.id
80 return super(stock_picking, self)._get_account_analytic_invoice(cursor,
81 user, picking, move_line)
83 def _invoice_line_hook(self, cursor, user, move_line, invoice_line_id):
84 return super(stock_picking, self)._invoice_line_hook(cursor, user,
85 move_line, invoice_line_id)
87 def _invoice_hook(self, cursor, user, picking, invoice_id):
88 purchase_obj = self.pool.get('purchase.order')
89 if picking.purchase_id:
90 purchase_obj.write(cursor, user, [picking.purchase_id.id], {'invoiced':True,
91 'invoice_id': invoice_id,
93 return super(stock_picking, self)._invoice_hook(cursor, user,
98 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: