1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import osv, fields
24 class stock_move(osv.osv):
25 _inherit = 'stock.move'
27 'purchase_line_id': fields.many2one('purchase.order.line',
28 'Purchase Order Line', ondelete='set null', select=True,
32 'purchase_line_id': lambda *a:False
37 # Inherit of picking to add the link to the PO
39 class stock_picking(osv.osv):
40 _inherit = 'stock.picking'
42 'purchase_id': fields.many2one('purchase.order', 'Purchase Order',
43 ondelete='set null', select=True, readonly=True),
46 'purchase_id': lambda *a: False,
49 def get_currency_id(self, cursor, user, picking):
50 if picking.purchase_id:
51 return picking.purchase_id.pricelist_id.currency_id.id
53 return super(stock_picking, self).get_currency_id(cursor, user, picking)
55 def _get_comment_invoice(self, cursor, user, picking):
56 if picking.purchase_id and picking.purchase_id.notes:
58 return picking.note + '\n' + picking.purchase_id.notes
60 return picking.purchase_id.notes
61 return super(stock_picking, self)._get_comment_invoice(cursor, user,
64 def _get_price_unit_invoice(self, cursor, user, move_line, type):
65 if move_line.purchase_line_id:
66 return move_line.purchase_line_id.price_unit
67 return super(stock_picking, self)._get_price_unit_invoice(cursor,
68 user, move_line, type)
70 def _get_discount_invoice(self, cursor, user, move_line):
71 if move_line.purchase_line_id:
73 return super(stock_picking, self)._get_discount_invoice(cursor, user,
76 def _get_taxes_invoice(self, cursor, user, move_line, type):
77 if move_line.purchase_line_id:
78 return [x.id for x in move_line.purchase_line_id.taxes_id]
79 return super(stock_picking, self)._get_taxes_invoice(cursor, user,
82 def _get_account_analytic_invoice(self, cursor, user, picking, move_line):
83 if move_line.purchase_line_id:
84 return move_line.purchase_line_id.account_analytic_id.id
85 return super(stock_picking, self)._get_account_analytic_invoice(cursor,
86 user, picking, move_line)
88 def _invoice_line_hook(self, cursor, user, move_line, invoice_line_id):
89 return super(stock_picking, self)._invoice_line_hook(cursor, user,
90 move_line, invoice_line_id)
92 def _invoice_hook(self, cursor, user, picking, invoice_id):
93 purchase_obj = self.pool.get('purchase.order')
94 if picking.purchase_id:
95 purchase_obj.write(cursor, user, [picking.purchase_id.id], {'invoice_id': invoice_id,
97 return super(stock_picking, self)._invoice_hook(cursor, user,
102 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: