~eduardo-bayardo-bias/openobject-addons/addons_interface

« back to all changes in this revision

Viewing changes to concrete_sale_order/sale.py

  • Committer: Eduardo Bayardo
  • Date: 2017-08-22 22:28:29 UTC
  • Revision ID: eduardo.bayardo@bias.com.mx-20170822222829-atxt6n45eevaibgu
update 

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    _order = "line_id,delivery_time"
39
39
 
40
40
    def _get_line_id(self, cr, uid, context=None):
41
 
        res = False
42
 
        order_id = context.get('order_id',False)
43
 
        if order_id:
44
 
            order = self.pool.get('sale.order').browse(cr, uid, order_id)
45
 
            #res = order.order_line and order.order_line[0].id
46
 
            order_line = [x for x in order.order_line if x.product_id.type=='product']
47
 
            res = order_line and order_line[0].id
48
 
        return res
 
41
        res = self.get_line_id(cr, uid, context=context)
 
42
        return res and res.id
 
43
 
 
44
    def _get_product_id(self, cr, uid, context=None):
 
45
        res = self.get_line_id(cr, uid, context=context)
 
46
        return res and res.product_id.id
 
47
 
 
48
    def _get_product_uom(self, cr, uid, context=None):
 
49
        res = self.get_line_id(cr, uid, context=context)
 
50
        return res and res.product_uom.id
49
51
 
50
52
    def _shipping_compute(self, cr, uid, ids, name, args, context, where =''):
51
53
        if not ids: 
134
136
        return result
135
137
 
136
138
    _columns = {
137
 
        'line_id': fields.many2one('sale.order.line', 'Line', required=True, readonly=True),
 
139
        'line_id': fields.many2one('sale.order.line', 'Line', required=True),
138
140
        'order_id': fields.many2one('sale.order', 'Sale Order', ondelete="cascade", select=True, required=True, readonly=True),
139
141
        'load_time': fields.datetime('Load Time', help="Load Time", required=True),
140
142
        'delivery_time': fields.datetime('Delivery Time', help="Delivery Time", required=True),
141
 
        'product_id': fields.many2one('product.product', 'Product', required=True, select=True, readonly=True, domain=[('type','<>','service')]),
 
143
        'product_id': fields.many2one('product.product', 'Product', required=True, select=True, domain=[('type','<>','service')]),
142
144
        'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product UoM'), required=True),
143
 
        'product_uom': fields.many2one('product.uom', 'Unit of Measure', required=True, readonly=True),
 
145
        'product_uom': fields.many2one('product.uom', 'Unit of Measure', required=True),
144
146
        'partner_id': fields.related('order_id', 'partner_id', type='many2one', relation='res.partner', string='Partner', select=True, store=True, readonly=True),
145
147
        'user_id': fields.related('order_id', 'user_id', type='many2one', relation='res.users', string='Saleman', store=True, readonly=True),
146
148
        'delivery_spacing': fields.related('line_id', 'order_id', 'delivery_spacing', type='time', string='Delivery Spacing'),
166
168
    }
167
169
    _defaults = {
168
170
        'line_id': _get_line_id,
 
171
        'product_id': _get_product_id,
 
172
        'product_uom': _get_product_uom,
169
173
        'delivery_spacing':'00:00:00',
170
174
        'transfer_time':'00:00:00',
171
175
        'delivery_time':'00:00:00',
172
176
    }
173
177
 
174
 
 
 
178
    def get_line_id(self, cr, uid, context=None):
 
179
        res = False
 
180
        order_id = context.get('order_id',False)
 
181
        if order_id:
 
182
            order = self.pool.get('sale.order').browse(cr, uid, order_id)
 
183
            order_line = [x for x in order.order_line if x.product_id.type=='product']
 
184
            res = order_line and order_line[0]
 
185
            if not res:
 
186
                raise osv.except_osv(_('Error !'), _('El pedido no tiene productos del tipo "Almacenable"'))
 
187
        return res
175
188
 
176
189
sale_order_ticket()
177
190
 
298
311
        tick_obj = self.pool.get('sale.order.ticket')
299
312
        order_lines = so.line_id and [so.line_id] or [x for x in so.order_line if x.product_id.type=='product']
300
313
        ticket_ids = []
 
314
        if not order_lines:
 
315
            raise osv.except_osv(_('Error !'), _('El pedido no tiene productos del tipo "Almacenable"'))
301
316
        for line in order_lines:
302
317
            if line.product_id.categ_id.check_delivery:
303
318
                xfer = time.strptime(so.transfer_time, TM_FMT)