~openerp-commiter/openobject-addons/stable-sja-branch

« back to all changes in this revision

Viewing changes to sale_layout/sale_layout.py

  • Committer: sja-axelor
  • Date: 2009-10-13 09:52:57 UTC
  • Revision ID: suniljagyasi@gmail.com-20091013095257-8u26ww0r20z9y6ey
add

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-2008 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
from osv import fields,osv
 
23
from tools import config
 
24
 
 
25
class sale_order_line(osv.osv):
 
26
 
 
27
    def invoice_line_create(self, cr, uid, ids, context={}):
 
28
        new_ids=[]
 
29
        for line in self.browse(cr, uid, ids, context):
 
30
            if line.layout_type == 'article':
 
31
                new_ids.append(line.id)
 
32
        return super(sale_order_line, self).invoice_line_create(cr, uid, new_ids, context)
 
33
 
 
34
    def _onchange_sale_order_line_view(self, cr, uid, id, type, context={}, *args):
 
35
            temp ={}
 
36
            temp['value']= {}
 
37
            if (not type):
 
38
                return {}
 
39
            if type != 'article':
 
40
                temp = {'value': {
 
41
                        'product_id': False,
 
42
                        'uos_id': False,
 
43
                        'account_id': False,
 
44
                        'price_unit': False,
 
45
                        'price_subtotal': False,
 
46
                        'quantity': 0,
 
47
                        'discount': False,
 
48
                        'invoice_line_tax_id': False,
 
49
                        'account_analytic_id': False,
 
50
                        },
 
51
                    }
 
52
                if type == 'line':
 
53
                    temp['value']['name'] = ' '
 
54
                if type == 'break':
 
55
                    temp['value']['name'] = ' '
 
56
                if type == 'subtotal':
 
57
                    temp['value']['name'] = 'Sub Total'
 
58
                return temp
 
59
            return {}
 
60
 
 
61
    def create(self, cr, user, vals, context=None):
 
62
        if vals.has_key('layout_type'):
 
63
            if vals['layout_type'] == 'line':
 
64
                vals['name'] = ' '
 
65
            if vals['layout_type'] == 'break':
 
66
                vals['name'] = ' '
 
67
            if vals['layout_type'] != 'article':
 
68
                vals['product_uom_qty']= 0                
 
69
        return super(sale_order_line, self).create(cr, user, vals, context)
 
70
 
 
71
    def write(self, cr, user, ids, vals, context=None):
 
72
        if vals.has_key('layout_type'):
 
73
            if vals['layout_type'] == 'line':
 
74
                vals['name'] = ' '
 
75
            if vals['layout_type'] == 'break':
 
76
                vals['name'] = ' '
 
77
        return super(sale_order_line, self).write(cr, user, ids, vals, context)
 
78
 
 
79
    def copy(self, cr, uid, id, default=None, context=None):
 
80
        if default is None:
 
81
            default = {}
 
82
        default['layout_type'] = self.browse(cr, uid, id).layout_type
 
83
        return super(sale_order_line, self).copy(cr, uid, id, default, context)
 
84
    
 
85
 
 
86
    _name = "sale.order.line"
 
87
    _order = "order_id, sequence asc"
 
88
    _description = "Sale Order line"
 
89
    _inherit = "sale.order.line"
 
90
    _columns = {
 
91
        'layout_type': fields.selection([
 
92
                ('article','Product'),
 
93
                ('title','Title'),
 
94
                ('text','Note'),
 
95
                ('subtotal','Sub Total'),
 
96
                ('line','Separator Line'),
 
97
                ('break','Page Break'),]
 
98
            ,'Layout Type', select=True, required=True),
 
99
        'sequence': fields.integer('Sequence Number'), 
 
100
        'price_unit': fields.float('Unit Price', digits=(16, int(config['price_accuracy']))),
 
101
        'product_uom_qty': fields.float('Quantity (UoM)', digits=(16,2)),
 
102
        'product_uom': fields.many2one('product.uom', 'Product UoM'),       
 
103
    }   
 
104
 
 
105
    _defaults = {
 
106
        'layout_type': lambda *a: 'article',
 
107
    }
 
108
sale_order_line()
 
109
 
 
110
 
 
111
class one2many_mod2(fields.one2many):
 
112
    def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
 
113
        if not context:
 
114
            context = {}
 
115
        if not values:
 
116
            values = {}
 
117
        res = {}
 
118
        for id in ids:
 
119
            res[id] = []
 
120
        ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',ids),('layout_type','=','article')], limit=self._limit)
 
121
        for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
 
122
            res[r[self._fields_id]].append( r['id'] )
 
123
        return res
 
124
 
 
125
 
 
126
class sale_order(osv.osv):
 
127
 
 
128
    def copy(self, cr, uid, id, default=None, context=None):
 
129
        if default is None:
 
130
            default = {}
 
131
        default['order_line'] = False
 
132
        return super(sale_order, self).copy(cr, uid, id, default, context)
 
133
 
 
134
    _inherit = "sale.order"
 
135
    _columns = {
 
136
        'abstract_line_ids': fields.one2many('sale.order.line', 'order_id', 'Order Lines',readonly=True, states={'draft':[('readonly',False)]}),
 
137
        'order_line': one2many_mod2('sale.order.line', 'order_id', 'Order Lines',readonly=True, states={'draft':[('readonly',False)]}),
 
138
    }
 
139
sale_order()
 
140
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
141