1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 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_currency_id(self, cursor, user, picking):
51 if picking.purchase_id:
52 return picking.purchase_id.pricelist_id.currency_id.id
54 return super(stock_picking, self).get_currency_id(cursor, user, picking)
56 def _get_comment_invoice(self, cursor, user, picking):
57 if picking.purchase_id and picking.purchase_id.notes:
59 return picking.note + '\n' + picking.purchase_id.notes
61 return picking.purchase_id.notes
62 return super(stock_picking, self)._get_comment_invoice(cursor, user,
65 def _get_price_unit_invoice(self, cursor, user, move_line, type):
66 if move_line.purchase_line_id:
67 return move_line.purchase_line_id.price_unit
68 return super(stock_picking, self)._get_price_unit_invoice(cursor,
69 user, move_line, type)
71 def _get_discount_invoice(self, cursor, user, move_line):
72 if move_line.purchase_line_id:
74 return super(stock_picking, self)._get_discount_invoice(cursor, user,
77 def _get_taxes_invoice(self, cursor, user, move_line, type):
78 if move_line.purchase_line_id:
79 return [x.id for x in move_line.purchase_line_id.taxes_id]
80 return super(stock_picking, self)._get_taxes_invoice(cursor, user,
83 def _get_account_analytic_invoice(self, cursor, user, picking, move_line):
84 if move_line.purchase_line_id:
85 return move_line.purchase_line_id.account_analytic_id.id
86 return super(stock_picking, self)._get_account_analytic_invoice(cursor,
87 user, picking, move_line)
89 def _invoice_line_hook(self, cursor, user, move_line, invoice_line_id):
90 return super(stock_picking, self)._invoice_line_hook(cursor, user,
91 move_line, invoice_line_id)
93 def _invoice_hook(self, cursor, user, picking, invoice_id):
94 purchase_obj = self.pool.get('purchase.order')
95 if picking.purchase_id:
96 purchase_obj.write(cursor, user, [picking.purchase_id.id], {'invoice_id': invoice_id,
98 return super(stock_picking, self)._invoice_hook(cursor, user,
103 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: