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 ##############################################################################
23 from osv import osv, fields
25 from tools.translate import _
27 class sale_journal_invoice_type(osv.osv):
28 _name = 'sale_journal.invoice.type'
29 _description = 'Invoice Types'
31 'name': fields.char('Invoice Type', size=64, required=True),
32 'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the invoice type without removing it."),
33 'note': fields.text('Note'),
34 'invoicing_method': fields.selection([('simple','Non grouped'),('grouped','Grouped')], 'Invoicing method', required=True),
38 'invoicing_method': 'simple'
40 sale_journal_invoice_type()
42 #==============================================
43 # sale journal inherit
44 #==============================================
46 class res_partner(osv.osv):
47 _inherit = 'res.partner'
49 'property_invoice_type': fields.property(
50 'sale_journal.invoice.type',
52 relation = 'sale_journal.invoice.type',
53 string = "Invoicing Method",
56 group_name = "Accounting Properties",
57 help = "The type of journal used for sales and picking."),
61 class picking(osv.osv):
62 _inherit = "stock.picking"
64 'invoice_type_id': fields.many2one('sale_journal.invoice.type', 'Invoice Type', readonly=True)
69 _inherit = "sale.order"
71 'invoice_type_id': fields.many2one('sale_journal.invoice.type', 'Invoice Type')
73 def action_ship_create(self, cr, uid, ids, *args):
74 result = super(sale, self).action_ship_create(cr, uid, ids, *args)
75 for order in self.browse(cr, uid, ids, context={}):
76 pids = [ x.id for x in order.picking_ids]
77 self.pool.get('stock.picking').write(cr, uid, pids, {
78 'invoice_type_id': order.invoice_type_id and order.invoice_type_id.id or False,
82 def onchange_partner_id(self, cr, uid, ids, part):
83 result = super(sale, self).onchange_partner_id(cr, uid, ids, part)
85 itype = self.pool.get('res.partner').browse(cr, uid, part).property_invoice_type
87 result['value']['invoice_type_id'] = itype.id