136e7d68198ce0d1807ea0c310c213229f53ac87
[odoo/odoo.git] / addons / sale_journal / sale_journal.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 class sale_journal_invoice_type(osv.osv):
25     _name = 'sale_journal.invoice.type'
26     _description = 'Invoice Types'
27     _columns = {
28         'name': fields.char('Invoice Type', size=64, required=True),
29         'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the invoice type without removing it."),
30         'note': fields.text('Note'),
31         'invoicing_method': fields.selection([('simple', 'Non grouped'), ('grouped', 'Grouped')], 'Invoicing method', required=True),
32     }
33     _defaults = {
34         'active': True,
35         'invoicing_method': 'simple'
36     }
37 sale_journal_invoice_type()
38
39 #==============================================
40 # sale journal inherit
41 #==============================================
42
43 class res_partner(osv.osv):
44     _inherit = 'res.partner'
45     _columns = {
46         'property_invoice_type': fields.property(
47             'sale_journal.invoice.type',
48             type = 'many2one',
49             relation = 'sale_journal.invoice.type',
50             string = "Invoicing Method",
51             view_load = True,
52             group_name = "Accounting Properties",
53             help = "The type of journal used for sales and picking."),
54     }
55 res_partner()
56
57 class picking(osv.osv):
58     _inherit = "stock.picking"
59     _columns = {
60         'invoice_type_id': fields.many2one('sale_journal.invoice.type', 'Invoice Type', readonly=True)
61     }
62 picking()
63
64 class sale(osv.osv):
65     _inherit = "sale.order"
66     _columns = {
67         'invoice_type_id': fields.many2one('sale_journal.invoice.type', 'Invoice Type')
68     }
69     def action_ship_create(self, cr, uid, ids, *args):
70         result = super(sale, self).action_ship_create(cr, uid, ids, *args)
71         obj_stock_pick = self.pool.get('stock.picking')
72         for order in self.browse(cr, uid, ids, context={}):
73             pids = [ x.id for x in order.picking_ids]
74             self.pool.get('stock.picking').write(cr, uid, pids, {
75                 'invoice_type_id': order.invoice_type_id and order.invoice_type_id.id or False,
76             })
77         return result
78
79     def onchange_partner_id(self, cr, uid, ids, part):
80         result = super(sale, self).onchange_partner_id(cr, uid, ids, part)
81         if part:
82             itype = self.pool.get('res.partner').browse(cr, uid, part).property_invoice_type
83             if itype:
84                 result['value']['invoice_type_id'] = itype.id
85         return result
86
87 sale()