[REF] purchase: search view of purchase order and form view of merge order wizard
[odoo/odoo.git] / addons / sale_journal / sale_journal_inherit.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from osv import osv, fields
23
24
25 class res_partner(osv.osv):
26     _inherit = 'res.partner'
27     _columns = {
28         'property_invoice_type': fields.property(
29         'sale_journal.invoice.type',
30         type='many2one',
31         relation='sale_journal.invoice.type',
32         string="Invoicing Method",
33         method=True,
34         view_load=True,
35         group_name="Accounting Properties",
36         help="The type of journal used for sales and picking."),
37     }
38 res_partner()
39
40 class picking(osv.osv):
41     _inherit="stock.picking"
42     _columns = {
43         'journal_id': fields.many2one('sale_journal.picking.journal', 'Journal'),
44         'sale_journal_id': fields.many2one('sale_journal.sale.journal', 'Sale Journal'),
45         'invoice_type_id': fields.many2one('sale_journal.invoice.type', 'Invoice Type', readonly=True)
46     }
47 picking()
48
49 class sale(osv.osv):
50     _inherit="sale.order"
51     _columns = {
52         'journal_id': fields.many2one('sale_journal.sale.journal', 'Journal'),
53         'invoice_type_id': fields.many2one('sale_journal.invoice.type', 'Invoice Type')
54     }
55     def action_ship_create(self, cr, uid, ids, *args):
56         result = super(sale, self).action_ship_create(cr, uid, ids, *args)
57         for order in self.browse(cr, uid, ids, context={}):
58             pids = [ x.id for x in order.picking_ids]
59             self.pool.get('stock.picking').write(cr, uid, pids, {
60                 'invoice_type_id': order.invoice_type_id.id,
61                 'sale_journal_id': order.journal_id.id
62             })
63         return result
64
65     def onchange_partner_id(self, cr, uid, ids, part):
66         result = super(sale, self).onchange_partner_id(cr, uid, ids, part)
67         if part:
68             itype = self.pool.get('res.partner').browse(cr, uid, part).property_invoice_type.id
69             result['value']['invoice_type_id'] = itype
70         return result
71 sale()
72 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
73