Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

ON change function in sale order line (warehouse per location)

By
Alcaline
on 10/1/14, 4:14 AM 1,182 views

I override the product_id_change in sale_order_line to get the quantity on hand and location per product but i'm recieving an error: SyntaxError: non-default argument follows default argument.

   def product_id_change11(self, cr, uid, ids, location_id='', pricelist, product, qty=0,
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
             lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
       
       location_id= {},
        netsvc.Logger().notifyChannel("NETSV 111111111111111111111111111111111111111111111111111111111111111111111111 ", netsvc.LOG_INFO, ' ' + str(location_id))
         context = context or {}
         netsvc.Logger().notifyChannel("NETSV 2222222222222222222222222222222222222222222222222222222222222222222222222222", netsvc.LOG_INFO, ' ' + str(context))
         lang = lang or context.get('lang',False)
         netsvc.Logger().notifyChannel("NETSV 3333333333333333333333333333333333333333333333333333333333333333333333333333333333", netsvc.LOG_INFO, ' ' + str(partner_id))
         if not partner_id:
             raise osv.except_osv(_('No Customer Defined !'), _('Before choosing a product,\n select a customer in the sales form.'))
         warning = {}
         product_uom_obj = self.pool.get('product.uom')
         partner_obj = self.pool.get('res.partner')
         product_obj = self.pool.get('product.product')
         context = {'lang': lang, 'partner_id': partner_id}
         if partner_id:
             lang = partner_obj.browse(cr, uid, partner_id).lang
         context_partner = {'lang': lang, 'partner_id': partner_id}
        
         if not product:
              return {'value': {'product_qty': 0.0, 'product_uom': False, 'th_weight': 0,
                 'product_uos_qty': qty}, 'domain': {'product_uom': [],
                    'product_uos': []}}
         obj_product = product_obj.browse(cr, uid, product)
         uom = uom or obj_product.uom_id.id
         amount = self.pool.get('stock.location')._product_get(cr, uid, location_id, [product], {'uom': uom, 'to_date': to_date})[product]
         result = {'product_qty': amount, 'product_uom': uom}
         return {'value': result}
               if not date_order:
             date_order = time.strftime(DEFAULT_SERVER_DATE_FORMAT)

         result = {}
         warning_msgs = ''
         product_obj = product_obj.browse(cr, uid, product, context=context_partner)
         uom2 = False
         if uom:
             uom2 = product_uom_obj.browse(cr, uid, uom)
             if product_obj.uom_id.category_id.id != uom2.category_id.id:
                 uom = False
         if uos:
             if product_obj.uos_id:
                 uos2 = product_uom_obj.browse(cr, uid, uos)
                 if product_obj.uos_id.category_id.id != uos2.category_id.id:
                     uos = False
             else:
                 uos = False
         fpos = fiscal_position and self.pool.get('account.fiscal.position').browse(cr, uid, fiscal_position) or False
         if update_tax: #The quantity only have changed
             result['tax_id'] = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, product_obj.taxes_id)

         if not flag:
             result['name'] = self.pool.get('product.product').name_get(cr, uid, [product_obj.id], context=context_partner)[0][1]
             if product_obj.description_sale:
                 result['name'] += '\n'+product_obj.description_sale
         domain = {}
         if (not uom) and (not uos):
             result['product_uom'] = product_obj.uom_id.id
             if product_obj.uos_id:
                 result['product_uos'] = product_obj.uos_id.id
                 result['product_uos_qty'] = qty * product_obj.uos_coeff
                 uos_category_id = product_obj.uos_id.category_id.id
             else:
                 result['product_uos'] = False
                 result['product_uos_qty'] = qty
                 uos_category_id = False
             result['th_weight'] = qty * product_obj.weight
             domain = {'product_uom':
                         [('category_id', '=', product_obj.uom_id.category_id.id)],
                         'product_uos':
                         [('category_id', '=', uos_category_id)]}
         elif uos and not uom: only happens if uom is False
             result['product_uom'] = product_obj.uom_id and product_obj.uom_id.id
             result['product_uom_qty'] = qty_uos / product_obj.uos_coeff
             result['th_weight'] = result['product_uom_qty'] * product_obj.weight
         elif uom:  whether uos is set or not
             default_uom = product_obj.uom_id and product_obj.uom_id.id
             q = product_uom_obj._compute_qty(cr, uid, uom, qty, default_uom)
             if product_obj.uos_id:
                 result['product_uos'] = product_obj.uos_id.id
                 result['product_uos_qty'] = qty * product_obj.uos_coeff
             else:

                 result['product_uos'] = False
                 result['product_uos_qty'] = qty
             result['th_weight'] = q * product_obj.weight        # Round the quantity up

         if not uom2:
             uom2 = product_obj.uom_id
          get unit price

         if not pricelist:
             warn_msg = _('You have to select a pricelist or a customer in the sales form !\n'
                     'Please set one before choosing a product.')
             warning_msgs += _("No Pricelist ! : ") + warn_msg +"\n\n"
         else:
             price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist],
                     product, qty or 1.0, partner_id, {
                         'uom': uom or result.get('product_uom'),
                         'date': date_order,
                        })[pricelist]
             if price is False:
                 warn_msg = _("Cannot find a pricelist line matching this product and quantity.\n"
                         "You have to change either the product, the quantity or the pricelist.")

                 warning_msgs += _("No valid pricelist line found ! :") + warn_msg +"\n\n"
             else:
                 result.update({'price_unit': price})
         if warning_msgs:
             warning = {
                        'title': _('Configuration Error!'),
                        'message' : warning_msgs
                     }
         return {'value': result, 'domain': domain, 'warning': warning}

 

2

René Schuster

--René Schuster--
1560
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 10/2/14, 3:49 AM

The error message is kind of self-explanatory..

The error is in your function header:

def product_id_change11(self, cr, uid, ids, location_id='', pricelist, product, qty=0, uom=False, qty_uos=0, uos=False,
                                    name='', partner_id=False, lang=False, update_tax=True, date_order=False, packaging=False,
                                    fiscal_position=False, flag=False, context=None):

Python expects a specifitc argument order for 'arguments' and 'keyword arguments' / 'default arguments'. You pass pricelist and product after the keyword argument location_id. Thats not possible.

Change the argument order and try again.

 

Regards.

thanks Schuster, but I've already solve it.

Alcaline
on 10/2/14, 4:42 AM
0

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 10/1/14, 6:35 AM

Please specify more of a question on the matter. This just looks like a very summarised job instruction and that is not really what we look for here.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/1/14, 4:14 AM
Seen: 1182 times
Last updated: 3/16/15, 8:10 AM