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
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),
37 'active': lambda *a: True,
38 'invoicing_method': lambda *a:'simple'
40 sale_journal_invoice_type()
42 class sale_journal(osv.osv):
43 _name = 'sale_journal.sale.journal'
44 _description = 'Sale Journal'
46 'name': fields.char('Journal', size=64, required=True),
47 'code': fields.char('Code', size=16, required=True),
48 'user_id': fields.many2one('res.users', 'Responsible', required=True),
49 'date': fields.date('Journal date', required=True),
50 'date_created': fields.date('Creation date', readonly=True, required=True),
51 'date_validation': fields.date('Validation date', readonly=True),
52 'sale_stats_ids': fields.one2many("sale.journal.report", "journal_id", 'Sale Stats', readonly=True),
53 'state': fields.selection([
57 ], 'State', required=True, readonly=True),
58 'note': fields.text('Note'),
61 'date': lambda *a: time.strftime('%Y-%m-%d'),
62 'date_created': lambda *a: time.strftime('%Y-%m-%d'),
63 'user_id': lambda self,cr,uid,context: uid,
64 'state': lambda self,cr,uid,context: 'draft',
67 def button_sale_cancel(self, cr, uid, ids, context={}):
69 sale_ids = self.pool.get('sale.order').search(cr, uid, [('journal_id','=',id),('state','=','draft')])
70 for saleid in sale_ids:
71 wf_service = netsvc.LocalService("workflow")
72 wf_service.trg_validate(uid, 'sale.order', saleid, 'cancel', cr)
73 for (id,name) in self.name_get(cr, uid, ids):
74 message = _('Sale order of Journal') + " '" + name + "' "+ _("is cancelled")
75 self.log(cr, uid, id, message)
78 def button_sale_confirm(self, cr, uid, ids, context={}):
80 sale_ids = self.pool.get('sale.order').search(cr, uid, [('journal_id','=',id),('state','=','draft')])
81 for saleid in sale_ids:
82 wf_service = netsvc.LocalService("workflow")
83 wf_service.trg_validate(uid, 'sale.order', saleid, 'order_confirm', cr)
84 for (id,name) in self.name_get(cr, uid, ids):
85 message = _('Sale orders of Journal') + " '" + name + "' "+ _("is confirmed")
86 self.log(cr, uid, id, message)
89 def button_open(self, cr, uid, ids, context={}):
90 self.write(cr, uid, ids, {'state':'open'})
91 for (id,name) in self.name_get(cr, uid, ids):
92 message = _('Sale orders of Journal') + " '" + name + "' "+ _("is opened")
93 self.log(cr, uid, id, message)
96 def button_draft(self, cr, uid, ids, context={}):
97 self.write(cr, uid, ids, {'state':'draft'})
98 for (id,name) in self.name_get(cr, uid, ids):
99 message = _('Sale orders of Journal') + " '" + name + "' "+ _("is in draft state")
100 self.log(cr, uid, id, message)
103 def button_close(self, cr, uid, ids, context={}):
104 self.write(cr, uid, ids, {'state':'done', 'date_validation':time.strftime('%Y-%m-%d')})
105 for (id,name) in self.name_get(cr, uid, ids):
106 message = _('Sale orders of Journal') + " '" + name + "' "+ _("is closed")
107 self.log(cr, uid, id, message)
112 class picking_journal(osv.osv):
113 _name = 'sale_journal.picking.journal'
114 _description = 'Picking Journal'
116 'name': fields.char('Journal', size=64, required=True),
117 'code': fields.char('Code', size=16, required=True),
118 'user_id': fields.many2one('res.users', 'Responsible', required=True),
119 'date': fields.date('Journal date', required=True),
120 'date_created': fields.date('Creation date', readonly=True, required=True),
121 'date_validation': fields.date('Validation date', readonly=True),
122 'picking_stats_ids': fields.one2many("sale.journal.picking.report", "journal_id", 'Journal Stats', readonly=True),
123 'state': fields.selection([
127 ], 'Creation date', required=True, readonly=True),
128 'note': fields.text('Note'),
131 'date': lambda *a: time.strftime('%Y-%m-%d'),
132 'date_created': lambda *a: time.strftime('%Y-%m-%d'),
133 'user_id': lambda self,cr,uid,context: uid,
134 'state': lambda self,cr,uid,context: 'draft',
136 def button_picking_cancel(self, cr, uid, ids, context={}):
138 pick_ids = self.pool.get('stock.picking').search(cr, uid, [('journal_id','=',id)])
139 for pickid in pick_ids:
140 wf_service = netsvc.LocalService("workflow")
141 wf_service.trg_validate(uid, 'stock.picking', pickid, 'button_cancel', cr)
143 def button_open(self, cr, uid, ids, context={}):
144 self.write(cr, uid, ids, {'state':'open'})
146 def button_draft(self, cr, uid, ids, context={}):
147 self.write(cr, uid, ids, {'state':'draft'})
149 def button_close(self, cr, uid, ids, context={}):
150 self.write(cr, uid, ids, {'state':'done', 'date_validation':time.strftime('%Y-%m-%d')})
154 #==============================================
155 # sale journal inherit
156 #==============================================
158 class res_partner(osv.osv):
159 _inherit = 'res.partner'
161 'property_invoice_type': fields.property(
162 'sale_journal.invoice.type',
164 relation='sale_journal.invoice.type',
165 string="Invoicing Method",
168 group_name="Accounting Properties",
169 help="The type of journal used for sales and picking."),
173 class picking(osv.osv):
174 _inherit="stock.picking"
176 'journal_id': fields.many2one('sale_journal.picking.journal', 'Journal'),
177 'sale_journal_id': fields.many2one('sale_journal.sale.journal', 'Sale Journal'),
178 'invoice_type_id': fields.many2one('sale_journal.invoice.type', 'Invoice Type', readonly=True)
183 _inherit="sale.order"
185 'journal_id': fields.many2one('sale_journal.sale.journal', 'Journal'),
186 'invoice_type_id': fields.many2one('sale_journal.invoice.type', 'Invoice Type')
188 def action_ship_create(self, cr, uid, ids, *args):
189 result = super(sale, self).action_ship_create(cr, uid, ids, *args)
190 for order in self.browse(cr, uid, ids, context={}):
191 pids = [ x.id for x in order.picking_ids]
192 self.pool.get('stock.picking').write(cr, uid, pids, {
193 'invoice_type_id': order.invoice_type_id.id,
194 'sale_journal_id': order.journal_id.id
198 def onchange_partner_id(self, cr, uid, ids, part):
199 result = super(sale, self).onchange_partner_id(cr, uid, ids, part)
201 itype = self.pool.get('res.partner').browse(cr, uid, part).property_invoice_type.id
202 result['value']['invoice_type_id'] = itype
205 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: