1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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.
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.
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/>.
21 ##############################################################################
23 from osv import fields,osv
24 from tools import config
25 import decimal_precision as dp
26 from tools.translate import _
28 class sale_order_line(osv.osv):
30 def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
31 tax_obj = self.pool.get('account.tax')
32 cur_obj = self.pool.get('res.currency')
34 context = context or {}
35 for line in self.browse(cr, uid, ids, context=context):
36 if line.layout_type=='article':
37 return super(sale_order_line, self)._amount_line(cr, uid, ids, field_name, arg, context)
39 def invoice_line_create(self, cr, uid, ids, context={}):
42 for line in self.browse(cr, uid, ids, context):
43 if line.layout_type == 'article':
44 new_ids.append(line.id)
45 list_seq.append(line.sequence)
46 invoice_line_ids = super(sale_order_line, self).invoice_line_create(cr, uid, new_ids, context)
47 pool_inv_line = self.pool.get('account.invoice.line')
49 for obj_inv_line in pool_inv_line.browse(cr, uid, invoice_line_ids, context=context):
50 pool_inv_line.write(cr, uid, [obj_inv_line.id], {'sequence': list_seq[seq]}, context=context)
52 return invoice_line_ids
54 def onchange_sale_order_line_view(self, cr, uid, id, type, context={}, *args):
66 'price_subtotal': 0.0,
69 'invoice_line_tax_id': False,
70 'account_analytic_id': False,
71 'product_uom_qty':0.0,
75 temp['value']['name'] = ' '
77 temp['value']['name'] = ' '
78 if type == 'subtotal':
79 temp['value']['name'] = 'Sub Total'
83 def create(self, cr, user, vals, context=None):
84 if vals.has_key('layout_type'):
85 if vals['layout_type'] == 'line':
87 if vals['layout_type'] == 'break':
89 if vals['layout_type'] != 'article':
90 vals['product_uom_qty']= 0
91 return super(sale_order_line, self).create(cr, user, vals, context)
93 def write(self, cr, user, ids, vals, context=None):
94 if vals.has_key('layout_type'):
95 if vals['layout_type'] == 'line':
97 if vals['layout_type'] == 'break':
99 return super(sale_order_line, self).write(cr, user, ids, vals, context)
101 def copy(self, cr, uid, id, default=None, context=None):
104 default['layout_type'] = self.browse(cr, uid, id).layout_type
105 return super(sale_order_line, self).copy(cr, uid, id, default, context)
108 _name = "sale.order.line"
109 _order = "order_id, sequence asc"
110 _description = "Sale Order line"
111 _inherit = "sale.order.line"
113 'layout_type': fields.selection([
114 ('article','Product'),
117 ('subtotal','Sub Total'),
118 ('line','Separator Line'),
119 ('break','Page Break'),]
120 ,'Layout Type', select=True, required=True),
121 'sequence': fields.integer('Sequence Number'),
122 'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Sale Price'), readonly=True, states={'draft':[('readonly',False)]}),
123 'product_uom_qty': fields.float('Quantity (UoM)', digits=(16,2)),
124 'product_uom': fields.many2one('product.uom', 'Product UoM'),
128 'layout_type': lambda *a: 'article',
133 class one2many_mod2(fields.one2many):
134 def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
142 ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',ids),('layout_type','=','article')], limit=self._limit)
143 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
144 res[r[self._fields_id]].append( r['id'] )
148 class sale_order(osv.osv):
150 def copy(self, cr, uid, id, default=None, context=None):
153 default['order_line'] = False
154 return super(sale_order, self).copy(cr, uid, id, default, context)
156 _inherit = "sale.order"
158 'abstract_line_ids': fields.one2many('sale.order.line', 'order_id', 'Order Lines',readonly=True, states={'draft':[('readonly',False)]}),
159 'order_line': one2many_mod2('sale.order.line', 'order_id', 'Order Lines',readonly=True, states={'draft':[('readonly',False)]}),
164 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: