Esempio n. 1
0
 def _do_action(self, cr, uid, data, context):
     pool = pooler.get_pool(cr.dbname)
     report = pool.get(data['model']).browse(cr, uid, data['id'], context=context)
     res = ir.ir_get(cr, uid, 'action', 'client_print_multi', [report.model])
     id = filter(lambda r: r[1]==report.report_name, res)[0][0]
     res = ir.ir_del(cr, uid, id)
     return {}
Esempio n. 2
0
 def exp_ir_get(self, cr, uid, keys, args=None, meta=None, context=None):
     if not args:
         args=[]
     if not context:
         context={}
     res = ir.ir_get(cr,uid, keys, args, meta, context)
     return res
Esempio n. 3
0
 def exp_ir_get(self, cr, uid, keys, args=None, meta=None, context=None):
     if not args:
         args=[]
     if not context:
         context={}
     res = ir.ir_get(cr,uid, keys, args, meta, context)
     return res
Esempio n. 4
0
    def _parse_HPTYBY(self, partner, default_addresses, line_content, status):
        partner_table = pooler.get_pool(cr.dbname).get('res.partner')

        self.sr['sender'] = partner
        self.partner_id = partner
        self.partner_order_id = default_addresses[0]
        self.pricelist_id = ir.ir_get(self.cr, self.uid, 'meta', 'product.pricelist', [('res.partner', self.partner_id)])[0][2]
        orders=pooler.get_pool(cr.dbname).get("sale.order").search(self.cr, self.uid, [('client_order_ref', 'ilike', self.ordernum), ('partner_order_id',"=",self.partner_order_id)])
        if orders and len(orders)>0:
            status.add_warning("This client order reference (%s) already exists for this client" % self.ordernum, self.ordernum, self.timestamp_edi, self.sr['sender'])
Esempio n. 5
0
 def _parse_DART(self, line_content, status):
     products=pooler.get_pool(cr.dbname).get('product.product').search(self.cr, self.uid, [('ean13','=',line_content["barcode"]),])
     #sale_order_line_o=sale_order_line(self.cr, self.uid, self.deliverdate, self.partner_invoice_id, status)
     sale_order_line_o=sale_order_line(self.cr, self.uid, self, self.deliverdate)
     if len(products) != 1:
         status.add_error("unknown product: %s" % line_content["barcode"], self.ordernum, self.timestamp_edi, self.sr['sender'])
         return
     else:
         sale_order_line_o.product=products[0]
     sale_order_line_o.product_ean=line_content["barcode"]
     if (line_content["unit21"]==''):
         status.add_warning("Using default Unit Of Measure", self.ordernum, self.timestamp_edi, self.sr['sender'])
     else:
         uoms=pooler.get_pool(cr.dbname).get('product.uom').search(self.cr, self.uid, [('name', 'ilike', line_content["unit21"]),])
         if len(uoms) != 1:
             status.add_error("unknown uom: %s" % line_content["unit21"], self.ordernum, self.timestamp_edi, self.sr['sender'])
             return
         else:
             sale_order_line_o.uom=uoms[0]
     sale_order_line_o.quantity=float(line_content["quantity21"])
     sale_order_line_o.uoc_quantity=float(line_content["quantity59"])
     sale_order_line_o.lineid=line_content["line-num"]
     sale_order_line_o.partner_address=None
     sale_order_line_o.price=line_content["price"]
     if sale_order_line_o.partner==0:
         partner=self.partner_id
     else:
         partner=sale_order_line_o.partner
     pricelist_id = ir.ir_get(self.cr, self.uid, 'meta', 'product.pricelist', [('res.partner', partner)])[0][2]
     sale_order_line_o.price = pooler.get_pool(cr.dbname).get('product.pricelist').price_get(self.cr, self.uid, [pricelist_id], sale_order_line_o.product, sale_order_line_o.quantity)[pricelist_id]
     sale_order_line_o.pricelist_id=pricelist_id
     if float(line_content["price"])!=sale_order_line_o.price:
         status.add_warning("Price from EDI (%s) different from what we have (%s) for product %s" % (str(float(line_content["price"])), sale_order_line_o.price, line_content["barcode"]), self.ordernum, self.timestamp_edi, self.sr['sender'])
     product_infos = pooler.get_pool(cr.dbname).get('product.product').read(self.cr, self.uid, [sale_order_line_o.product])[0]
     if line_content['price-unit']=="":
         status.add_warning("Blank Unit Of Price for product %s should be %s" % (line_content['barcode'], product_infos['uos_id'][1]), self.ordernum, self.timestamp_edi, self.sr['sender'])
         sale_order_line_o.price_unit= product_infos['uos_id'][0]
     elif product_infos['uos_id'][1] != line_content['price-unit']:
         status.add_error('Invalid Unit Of Price for product %s Should be "%s" instead of "%s"' % (line_content['barcode'], product_infos['uos_id'][1], line_content["price-unit"]), self.ordernum, self.timestamp_edi, self.sr['sender'])
     else:
         sale_order_line_o.price_unit= product_infos['uos_id'][0]
     sale_order_line_o.price_unit_customer=float(line_content['hint-price'])
     sale_order_line_o.check(status)
     self.order_lines.append(sale_order_line_o)
Esempio n. 6
0
    def execute_cr(self, cr, uid, data, state='init', context=None):
        if not context:
            context={}
        res = {}
        try:
            state_def = self.states[state]

            result_def = state_def.get('result', {})
            
            actions_res = {}
            # iterate through the list of actions defined for this state
            for action in state_def.get('actions', []):
                # execute them
                action_res = action(self, cr, uid, data, context)
                assert isinstance(action_res, dict), 'The return value of wizard actions should be a dictionary'
                actions_res.update(action_res)
                
            res = copy.copy(result_def)
            res['datas'] = actions_res
            
            lang = context.get('lang', False)
            if result_def['type'] == 'action':
                res['action'] = result_def['action'](self, cr, uid, data, context)
            elif result_def['type'] == 'form':
                fields = copy.deepcopy(result_def['fields'])
                arch = copy.copy(result_def['arch'])
                button_list = copy.copy(result_def['state'])

                if isinstance(fields, UpdateableDict):
                    fields = fields.dict
                if isinstance(arch, UpdateableStr):
                    arch = arch.string

                # fetch user-set defaut values for the field... shouldn't we pass it the uid?
                defaults = ir.ir_get(cr, uid, 'default', False, [('wizard.'+self.wiz_name, False)])
                default_values = dict([(x[1], x[2]) for x in defaults])
                for val in fields.keys():
                    if 'default' in fields[val]:
                        # execute default method for this field
                        if callable(fields[val]['default']):
                            fields[val]['value'] = fields[val]['default'](uid, data, state)
                        else:
                            fields[val]['value'] = fields[val]['default']
                        del fields[val]['default']
                    else:
                        # if user has set a default value for the field, use it
                        if val in default_values:
                            fields[val]['value'] = default_values[val]
                    if 'selection' in fields[val]:
                        if not isinstance(fields[val]['selection'], (tuple, list)):
                            fields[val] = copy.copy(fields[val])
                            fields[val]['selection'] = fields[val]['selection'](self, cr, uid, context)
                        elif lang:
                            res_name = "%s,%s,%s" % (self.wiz_name, state, val)
                            trans = lambda x: translate(cr, res_name, 'selection', lang, x) or x
                            for idx, (key, val2) in enumerate(fields[val]['selection']):
                                fields[val]['selection'][idx] = (key, trans(val2))

                if lang:
                    # translate fields
                    for field in fields:
                        res_name = "%s,%s,%s" % (self.wiz_name, state, field)

                        trans = translate(cr, res_name, 'wizard_field', lang)
                        if trans:
                            fields[field]['string'] = trans

                        if 'help' in fields[field]:
                            t = translate(cr, res_name, 'help', lang, fields[field]['help']) 
                            if t:
                                fields[field]['help'] = t

                    # translate arch
                    if not isinstance(arch, UpdateableStr):
                        doc = etree.XML(arch)
                        self.translate_view(cr, doc, state, lang)
                        arch = etree.tostring(doc)

                    # translate buttons
                    button_list = list(button_list)
                    for i, aa  in enumerate(button_list):
                        button_name = aa[0]
                        trans = translate(cr, self.wiz_name+','+state+','+button_name, 'wizard_button', lang)
                        if trans:
                            aa = list(aa)
                            aa[1] = trans
                            button_list[i] = aa
                    
                res['fields'] = fields
                res['arch'] = arch
                res['state'] = button_list

            elif result_def['type'] == 'choice':
                next_state = result_def['next_state'](self, cr, uid, data, context)
                return self.execute_cr(cr, uid, data, next_state, context)
        
        except Exception, e:
            if isinstance(e, except_wizard) \
                or isinstance(e, except_osv) \
                or isinstance(e, except_orm):
                self.abortResponse(2, e.name, 'warning', e.value)
            else:
                import traceback
                tb_s = reduce(lambda x, y: x+y, traceback.format_exception(
                    sys.exc_type, sys.exc_value, sys.exc_traceback))
                logger = Logger()
                logger.notifyChannel("web-services", LOG_ERROR,
                        'Exception in call: ' + tb_s)
                raise
Esempio n. 7
0
    def execute_cr(self, cr, uid, data, state='init', context=None):
        if not context:
            context = {}
        res = {}
        try:
            state_def = self.states[state]

            result_def = state_def.get('result', {})

            actions_res = {}
            # iterate through the list of actions defined for this state
            for action in state_def.get('actions', []):
                # execute them
                action_res = action(self, cr, uid, data, context)
                assert isinstance(
                    action_res, dict
                ), 'The return value of wizard actions should be a dictionary'
                actions_res.update(action_res)

            res = copy.copy(result_def)
            res['datas'] = actions_res

            lang = context.get('lang', False)
            if result_def['type'] == 'action':
                res['action'] = result_def['action'](self, cr, uid, data,
                                                     context)
            elif result_def['type'] == 'form':
                fields = copy.deepcopy(result_def['fields'])
                arch = copy.copy(result_def['arch'])
                button_list = copy.copy(result_def['state'])

                if isinstance(fields, UpdateableDict):
                    fields = fields.dict
                if isinstance(arch, UpdateableStr):
                    arch = arch.string

                # fetch user-set defaut values for the field... shouldn't we pass it the uid?
                defaults = ir.ir_get(cr, uid, 'default', False,
                                     [('wizard.' + self.wiz_name, False)])
                default_values = dict([(x[1], x[2]) for x in defaults])
                for val in fields.keys():
                    if 'default' in fields[val]:
                        # execute default method for this field
                        if callable(fields[val]['default']):
                            fields[val]['value'] = fields[val]['default'](
                                uid, data, state)
                        else:
                            fields[val]['value'] = fields[val]['default']
                        del fields[val]['default']
                    else:
                        # if user has set a default value for the field, use it
                        if val in default_values:
                            fields[val]['value'] = default_values[val]
                    if 'selection' in fields[val]:
                        if not isinstance(fields[val]['selection'],
                                          (tuple, list)):
                            fields[val] = copy.copy(fields[val])
                            fields[val]['selection'] = fields[val][
                                'selection'](self, cr, uid, context)
                        elif lang:
                            res_name = "%s,%s,%s" % (self.wiz_name, state, val)
                            trans = lambda x: translate(
                                cr, res_name, 'selection', lang, x) or x
                            for idx, (key, val2) in enumerate(
                                    fields[val]['selection']):
                                fields[val]['selection'][idx] = (key,
                                                                 trans(val2))

                if lang:
                    # translate fields
                    for field in fields:
                        res_name = "%s,%s,%s" % (self.wiz_name, state, field)

                        trans = translate(cr, res_name, 'wizard_field', lang)
                        if trans:
                            fields[field]['string'] = trans

                        if 'help' in fields[field]:
                            t = translate(cr, res_name, 'help', lang,
                                          fields[field]['help'])
                            if t:
                                fields[field]['help'] = t

                    # translate arch
                    if not isinstance(arch, UpdateableStr):
                        doc = etree.XML(arch)
                        self.translate_view(cr, doc, state, lang)
                        arch = etree.tostring(doc)

                    # translate buttons
                    button_list = list(button_list)
                    for i, aa in enumerate(button_list):
                        button_name = aa[0]
                        trans = translate(
                            cr,
                            self.wiz_name + ',' + state + ',' + button_name,
                            'wizard_button', lang)
                        if trans:
                            aa = list(aa)
                            aa[1] = trans
                            button_list[i] = aa

                res['fields'] = fields
                res['arch'] = arch
                res['state'] = button_list

            elif result_def['type'] == 'choice':
                next_state = result_def['next_state'](self, cr, uid, data,
                                                      context)
                return self.execute_cr(cr, uid, data, next_state, context)

        except Exception, e:
            if isinstance(e, except_wizard) \
                or isinstance(e, except_osv) \
                or isinstance(e, except_orm):
                self.abortResponse(2, e.name, 'warning', e.value)
            else:
                import traceback
                tb_s = reduce(
                    lambda x, y: x + y,
                    traceback.format_exception(sys.exc_type, sys.exc_value,
                                               sys.exc_traceback))
                logger = Logger()
                logger.notifyChannel("web-services", LOG_ERROR,
                                     'Exception in call: ' + tb_s)
                raise