~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to sale_journal/sale_journal.py

  • Committer: Fabien Pinckaers
  • Date: 2008-11-12 06:43:12 UTC
  • Revision ID: fp@tinyerp.com-20081112064312-fp85io97i1e95tuz
moved

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##############################################################################
2
 
#
3
 
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
 
#                    Fabien Pinckaers <fp@tiny.Be>
5
 
#
6
 
# WARNING: This program as such is intended to be used by professional
7
 
# programmers who take the whole responsability of assessing all potential
8
 
# consequences resulting from its eventual inadequacies and bugs
9
 
# End users who are looking for a ready-to-use solution with commercial
10
 
# garantees and support are strongly adviced to contract a Free Software
11
 
# Service Company
12
 
#
13
 
# This program is Free Software; you can redistribute it and/or
14
 
# modify it under the terms of the GNU General Public License
15
 
# as published by the Free Software Foundation; either version 2
16
 
# of the License, or (at your option) any later version.
17
 
#
18
 
# This program is distributed in the hope that it will be useful,
19
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 
# GNU General Public License for more details.
22
 
#
23
 
# You should have received a copy of the GNU General Public License
24
 
# along with this program; if not, write to the Free Software
25
 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26
 
#
27
 
##############################################################################
28
 
 
29
 
from osv import osv, fields
30
 
import netsvc
31
 
import time
32
 
 
33
 
class sale_journal_invoice_type(osv.osv):
34
 
        _name = 'sale_journal.invoice.type'
35
 
        _description = 'Invoice Types'
36
 
        _columns = {
37
 
                'name': fields.char('Invoice Type', size=64, required=True),
38
 
                'active': fields.boolean('Active'),
39
 
                'note': fields.text('Note'),
40
 
                'invoicing_method': fields.selection([('simple','Non grouped'),('grouped','Grouped')], 'Invoicing method', required=True),
41
 
        }
42
 
        _defaults = {
43
 
                'active': lambda *a: True,
44
 
                'invoicing_method': lambda *a:'simple'
45
 
        }
46
 
sale_journal_invoice_type()
47
 
 
48
 
class sale_journal(osv.osv):
49
 
        _name = 'sale_journal.sale.journal'
50
 
        _description = 'Sale Journal'
51
 
        _columns = {
52
 
                'name': fields.char('Journal', size=64, required=True),
53
 
                'code': fields.char('Code', size=16, required=True),
54
 
                'user_id': fields.many2one('res.users', 'Responsible', required=True),
55
 
                'date': fields.date('Journal date', required=True),
56
 
                'date_created': fields.date('Creation date', readonly=True, required=True),
57
 
                'date_validation': fields.date('Validation date', readonly=True),
58
 
                'sale_stats_ids': fields.one2many("sale_journal.sale.stats", "journal_id", 'Sale Stats', readonly=True),
59
 
                'state': fields.selection([
60
 
                        ('draft','Draft'),
61
 
                        ('open','Open'),
62
 
                        ('done','Done'),
63
 
                ], 'State', required=True),
64
 
                'note': fields.text('Note'),
65
 
        }
66
 
        _defaults = {
67
 
                'date': lambda *a: time.strftime('%Y-%m-%d'),
68
 
                'date_created': lambda *a: time.strftime('%Y-%m-%d'),
69
 
                'user_id': lambda self,cr,uid,context: uid,
70
 
                'state': lambda self,cr,uid,context: 'draft',
71
 
        }
72
 
        def button_sale_cancel(self, cr, uid, ids, context={}):
73
 
                for id in ids:
74
 
                        sale_ids = self.pool.get('sale.order').search(cr, uid, [('journal_id','=',id),('state','=','draft')])
75
 
                        for saleid in sale_ids:
76
 
                                wf_service = netsvc.LocalService("workflow")
77
 
                                wf_service.trg_validate(uid, 'sale.order', saleid, 'cancel', cr)
78
 
                return True
79
 
        def button_sale_confirm(self, cr, uid, ids, context={}):
80
 
                for id in ids:
81
 
                        sale_ids = self.pool.get('sale.order').search(cr, uid, [('journal_id','=',id),('state','=','draft')])
82
 
                        for saleid in sale_ids:
83
 
                                wf_service = netsvc.LocalService("workflow")
84
 
                                wf_service.trg_validate(uid, 'sale.order', saleid, 'order_confirm', cr)
85
 
                return True
86
 
 
87
 
        def button_open(self, cr, uid, ids, context={}):
88
 
                self.write(cr, uid, ids, {'state':'open'})
89
 
                return True
90
 
        def button_draft(self, cr, uid, ids, context={}):
91
 
                self.write(cr, uid, ids, {'state':'draft'})
92
 
                return True
93
 
        def button_close(self, cr, uid, ids, context={}):
94
 
                self.write(cr, uid, ids, {'state':'done', 'date_validation':time.strftime('%Y-%m-%d')})
95
 
                return True
96
 
sale_journal()
97
 
 
98
 
class picking_journal(osv.osv):
99
 
        _name = 'sale_journal.picking.journal'
100
 
        _description = 'Packings Journal'
101
 
        _columns = {
102
 
                'name': fields.char('Journal', size=64, required=True),
103
 
                'code': fields.char('Code', size=16, required=True),
104
 
                'user_id': fields.many2one('res.users', 'Responsible', required=True),
105
 
                'date': fields.date('Journal date', required=True),
106
 
                'date_created': fields.date('Creation date', readonly=True, required=True),
107
 
                'date_validation': fields.date('Validation date', readonly=True),
108
 
                'picking_stats_ids': fields.one2many("sale_journal.picking.stats", "journal_id", 'Journal Stats', readonly=True),
109
 
                'state': fields.selection([
110
 
                        ('draft','Draft'),
111
 
                        ('open','Open'),
112
 
                        ('done','Done'),
113
 
                ], 'Creation date', required=True),
114
 
                'note': fields.text('Note'),
115
 
        }
116
 
        _defaults = {
117
 
                'date': lambda *a: time.strftime('%Y-%m-%d'),
118
 
                'date_created': lambda *a: time.strftime('%Y-%m-%d'),
119
 
                'user_id': lambda self,cr,uid,context: uid,
120
 
                'state': lambda self,cr,uid,context: 'draft',
121
 
        }
122
 
        def button_picking_cancel(self, cr, uid, ids, context={}):
123
 
                for id in ids:
124
 
                        pick_ids = self.pool.get('stock.picking').search(cr, uid, [('journal_id','=',id)])
125
 
                        for pickid in pick_ids:
126
 
                                wf_service = netsvc.LocalService("workflow")
127
 
                                wf_service.trg_validate(uid, 'stock.picking', pickid, 'button_cancel', cr)
128
 
                return True
129
 
        def button_open(self, cr, uid, ids, context={}):
130
 
                self.write(cr, uid, ids, {'state':'open'})
131
 
                return True
132
 
        def button_draft(self, cr, uid, ids, context={}):
133
 
                self.write(cr, uid, ids, {'state':'draft'})
134
 
                return True
135
 
        def button_close(self, cr, uid, ids, context={}):
136
 
                self.write(cr, uid, ids, {'state':'done', 'date_validation':time.strftime('%Y-%m-%d')})
137
 
                return True
138
 
picking_journal()
139