~sharoonthomas/openerpretail/core

« back to all changes in this revision

Viewing changes to bin/addons/sale_journal/sale_journal.py

  • Committer: Sharoon Thomas
  • Date: 2009-07-20 06:25:34 UTC
  • Revision ID: sharoonthomas@teagarden.in-20090720062534-j8jq2nmdy63w9o9c
Initial Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from osv import osv, fields
 
24
import netsvc
 
25
import time
 
26
 
 
27
class sale_journal_invoice_type(osv.osv):
 
28
    _name = 'sale_journal.invoice.type'
 
29
    _description = 'Invoice Types'
 
30
    _columns = {
 
31
        'name': fields.char('Invoice Type', size=64, required=True),
 
32
        'active': fields.boolean('Active'),
 
33
        'note': fields.text('Note'),
 
34
        'invoicing_method': fields.selection([('simple','Non grouped'),('grouped','Grouped')], 'Invoicing method', required=True),
 
35
    }
 
36
    _defaults = {
 
37
        'active': lambda *a: True,
 
38
        'invoicing_method': lambda *a:'simple'
 
39
    }
 
40
sale_journal_invoice_type()
 
41
 
 
42
class sale_journal(osv.osv):
 
43
    _name = 'sale_journal.sale.journal'
 
44
    _description = 'Sale Journal'
 
45
    _columns = {
 
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.sale.stats", "journal_id", 'Sale Stats', readonly=True),
 
53
        'state': fields.selection([
 
54
            ('draft','Draft'),
 
55
            ('open','Open'),
 
56
            ('done','Done'),
 
57
        ], 'State', required=True),
 
58
        'note': fields.text('Note'),
 
59
    }
 
60
    _defaults = {
 
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',
 
65
    }
 
66
    def button_sale_cancel(self, cr, uid, ids, context={}):
 
67
        for id in ids:
 
68
            sale_ids = self.pool.get('sale.order').search(cr, uid, [('journal_id','=',id),('state','=','draft')])
 
69
            for saleid in sale_ids:
 
70
                wf_service = netsvc.LocalService("workflow")
 
71
                wf_service.trg_validate(uid, 'sale.order', saleid, 'cancel', cr)
 
72
        return True
 
73
    def button_sale_confirm(self, cr, uid, ids, context={}):
 
74
        for id in ids:
 
75
            sale_ids = self.pool.get('sale.order').search(cr, uid, [('journal_id','=',id),('state','=','draft')])
 
76
            for saleid in sale_ids:
 
77
                wf_service = netsvc.LocalService("workflow")
 
78
                wf_service.trg_validate(uid, 'sale.order', saleid, 'order_confirm', cr)
 
79
        return True
 
80
 
 
81
    def button_open(self, cr, uid, ids, context={}):
 
82
        self.write(cr, uid, ids, {'state':'open'})
 
83
        return True
 
84
    def button_draft(self, cr, uid, ids, context={}):
 
85
        self.write(cr, uid, ids, {'state':'draft'})
 
86
        return True
 
87
    def button_close(self, cr, uid, ids, context={}):
 
88
        self.write(cr, uid, ids, {'state':'done', 'date_validation':time.strftime('%Y-%m-%d')})
 
89
        return True
 
90
sale_journal()
 
91
 
 
92
class picking_journal(osv.osv):
 
93
    _name = 'sale_journal.picking.journal'
 
94
    _description = 'Packing Journal'
 
95
    _columns = {
 
96
        'name': fields.char('Journal', size=64, required=True),
 
97
        'code': fields.char('Code', size=16, required=True),
 
98
        'user_id': fields.many2one('res.users', 'Responsible', required=True),
 
99
        'date': fields.date('Journal date', required=True),
 
100
        'date_created': fields.date('Creation date', readonly=True, required=True),
 
101
        'date_validation': fields.date('Validation date', readonly=True),
 
102
        'picking_stats_ids': fields.one2many("sale_journal.picking.stats", "journal_id", 'Journal Stats', readonly=True),
 
103
        'state': fields.selection([
 
104
            ('draft','Draft'),
 
105
            ('open','Open'),
 
106
            ('done','Done'),
 
107
        ], 'Creation date', required=True),
 
108
        'note': fields.text('Note'),
 
109
    }
 
110
    _defaults = {
 
111
        'date': lambda *a: time.strftime('%Y-%m-%d'),
 
112
        'date_created': lambda *a: time.strftime('%Y-%m-%d'),
 
113
        'user_id': lambda self,cr,uid,context: uid,
 
114
        'state': lambda self,cr,uid,context: 'draft',
 
115
    }
 
116
    def button_picking_cancel(self, cr, uid, ids, context={}):
 
117
        for id in ids:
 
118
            pick_ids = self.pool.get('stock.picking').search(cr, uid, [('journal_id','=',id)])
 
119
            for pickid in pick_ids:
 
120
                wf_service = netsvc.LocalService("workflow")
 
121
                wf_service.trg_validate(uid, 'stock.picking', pickid, 'button_cancel', cr)
 
122
        return True
 
123
    def button_open(self, cr, uid, ids, context={}):
 
124
        self.write(cr, uid, ids, {'state':'open'})
 
125
        return True
 
126
    def button_draft(self, cr, uid, ids, context={}):
 
127
        self.write(cr, uid, ids, {'state':'draft'})
 
128
        return True
 
129
    def button_close(self, cr, uid, ids, context={}):
 
130
        self.write(cr, uid, ids, {'state':'done', 'date_validation':time.strftime('%Y-%m-%d')})
 
131
        return True
 
132
picking_journal()
 
133
 
 
134
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
135