示例#1
0
 def test_03(self, ctx):
     if not ctx.get('dry_run', False):
         wchar_string = u"- Unicode string àèìòù"
         os0.wlog(wchar_string)
         # if wlog fails follow statemente is not executed
     sts = self.Z.test_result(ctx, "Check for unicode support", True, True)
     if not ctx.get('dry_run', False):
         x = unichr(0x3b1) + unichr(0x3b2) + unichr(0x3b3)
         os0.wlog("- Greek letters", x)
     sts = self.Z.test_result(ctx, "- Greek letters", True, True)
     res = None
     ustr = None
     bstr = None
     if not ctx.get('dry_run', False):
         res = os0.str2bool('true', None)
     sts = self.Z.test_result(ctx, "str2bool(true)", True, res)
     if not ctx.get('dry_run', False):
         res = os0.str2bool('0', None)
     sts = self.Z.test_result(ctx, "str2bool(0)", False, res)
     if not ctx.get('dry_run', False):
         res = os0.str2bool(False, None)
     sts = self.Z.test_result(ctx, "str2bool(0)", False, res)
     if not ctx.get('dry_run', False):
         res = os0.str2bool('invalid', False)
     sts = self.Z.test_result(ctx, "str2bool(0)", False, res)
     if not ctx.get('dry_run', False):
         res = os0.nakedname('myfile')
     sts = self.Z.test_result(ctx, "nakedname(myfile)", 'myfile', res)
     if not ctx.get('dry_run', False):
         res = os0.nakedname('myfile.py')
     sts = self.Z.test_result(ctx, "nakedname(myfile.py)", 'myfile', res)
     if not ctx.get('dry_run', False):
         bstr = 'text àèìòù'
         ustr = u"text àèìòù"
         res = os0.u(bstr)
     sts = self.Z.test_result(ctx, "unicode(string)", ustr, res)
     sts = self.Z.test_result(ctx, "unicode(string)", ustr, os0.u(ustr))
     if not ctx.get('dry_run', False):
         bstr = 'text àèìòù'
         ustr = u"text àèìòù"
         res = os0.b(ustr)
     sts = self.Z.test_result(ctx, "bstring(string)", bstr, res)
     sts = self.Z.test_result(ctx, "bstring(string)", os0.b(bstr), res)
     return sts
示例#2
0
文件: zarlib.py 项目: tate11/tools
def create_def_params_dict(ctx):
    """Create default params dictionary"""
    opt_obj = ctx.get('_opt_obj', None)
    conf_obj = ctx.get('_conf_obj', None)
    # s = "options"
    s = "Environment"
    if conf_obj:
        if not conf_obj.has_section(s):
            conf_obj.add_section(s)
        for p in LX_CFG_S:
            ctx[p] = conf_obj.get(s, p)
        for p in LX_CFG_B:
            ctx[p] = conf_obj.getboolean(s, p)
    else:
        DEFDCT = default_conf(ctx)
        for p in LX_CFG_S:
            if p in DEFDCT:
                ctx[p] = DEFDCT[p]
        for p in LX_CFG_B:
            if p in DEFDCT:
                ctx[p] = DEFDCT[p]
    if opt_obj:
        for p in LX_OPT_S:
            if p in LX_OPT_OPPONENT:
                a = LX_OPT_OPPONENT[p]
                if hasattr(opt_obj, a) and \
                        getattr(opt_obj, a) is False:
                    ctx[p] = False
                elif hasattr(opt_obj, p) and \
                        getattr(opt_obj, p):
                    ctx[p] = True
                else:
                    ctx[p] = None
            elif hasattr(opt_obj, p):
                ctx[p] = getattr(opt_obj, p)
        for p in LX_OPT_B:
            if hasattr(opt_obj, p):
                ctx[p] = os0.str2bool(getattr(opt_obj, p), None)
        for p in LX_OPT_N:
            if hasattr(opt_obj, p) and getattr(opt_obj, p):
                ctx[p] = int(getattr(opt_obj, p))
    for p in LX_CFG_SB:
        ctx[p] = os0.str2bool(ctx[p], ctx[p])
    return ctx
示例#3
0
def create_def_params_dict(ctx):
    """Create default params dictionary"""
    opt_obj = ctx.get('_opt_obj', None)
    conf_obj = ctx.get('_conf_obj', None)
    s = "options"
    if conf_obj and not conf_obj.has_section(s):
        conf_obj.add_section(s)
    DEFDCT = default_conf(ctx)
    for p in LX_CFG_S:
        v = get_versioned_option(conf_obj, s, p, defval=DEFDCT)
        if v is not None:
            ctx[p] = v
    for p in LX_CFG_B:
        v = get_versioned_option(conf_obj, s, p, is_bool=True)
        if v is not None:
            ctx[p] = v
    if opt_obj:
        for p in LX_OPT_S:
            if p in LX_OPT_OPPONENT:
                a = LX_OPT_OPPONENT[p]
                if hasattr(opt_obj, a) and \
                        getattr(opt_obj, a) is False:
                    ctx[p] = False
                elif hasattr(opt_obj, p) and \
                        getattr(opt_obj, p):
                    ctx[p] = True
                else:
                    ctx[p] = None
            elif hasattr(opt_obj, p):
                tmp = getattr(opt_obj, p)
                if p not in ctx or tmp:
                    ctx[p] = tmp
        for p in LX_OPT_B:
            if hasattr(opt_obj, p):
                ctx[p] = os0.str2bool(getattr(opt_obj, p), None)
        for p in LX_OPT_N:
            if hasattr(opt_obj, p) and getattr(opt_obj, p):
                ctx[p] = int(getattr(opt_obj, p))
    for p in LX_CFG_SB:
        ctx[p] = os0.str2bool(ctx[p], ctx[p])
    if ctx.get('LX_CFG_S', ''):
        ctx['LX_CFG_S'] = eval(ctx['LX_CFG_S'])
    return ctx
示例#4
0
def create_def_params_dict(opt_obj, conf_obj):
    """Create default params dictionary"""
    prm = {}
    s = "options"
    if conf_obj:
        if not conf_obj.has_section(s):
            conf_obj.add_section(s)
        for p in LX_CFG_S:
            prm[p] = conf_obj.get(s, p)
        for p in LX_CFG_B:
            prm[p] = conf_obj.getboolean(s, p)
    for p in LX_CFG_SB:
        prm[p] = os0.str2bool(prm[p], prm[p])
    for p in LX_OPT_CFG_S:
        if hasattr(opt_obj, p):
            prm[p] = getattr(opt_obj, p)
    return prm
示例#5
0
def drop_unchanged_fields(ctx, vals, model, xid):
    rec = None
    if model and xid:
        rec = clodoo.browseL8(ctx, model, xid)
    for field in vals.copy():
        attrs = ctx['STRUCT'][model].get(field, {})
        if not attrs:
            del vals[field]
        if rec:
            if attrs['ttype'] == 'many2one':
                if rec[field] and vals[field] == rec[field].id:
                    del vals[field]
            elif attrs['ttype'] == 'boolean':
                if isinstance(vals[field], bool) and vals[field] == rec[field]:
                    del vals[field]
                elif os0.str2bool(vals[field], False) == rec[field]:
                    del vals[field]
            elif (isinstance(vals[field], (basestring, int)) and
                  vals[field] == rec[field]):
                del vals[field]
    return vals
示例#6
0
    def bind_fields(self,
                    model,
                    vals,
                    company_id,
                    parent_id=None,
                    parent_model=None,
                    how_id=None):
        """TODO: write implementation"""
        self.setup_model_structure(model)
        model_model = self.env[model]
        parent_name = ''
        for field in vals.copy():
            if how_id == 'del':
                del vals[field]
                continue
            elif how_id == 'keep':
                continue
            attrs = self.STRUCT[model].get(field, {})
            if not attrs:
                if (model == 'account.payment.term.line' and field == 'months'
                        and vals[field]):
                    vals['days'] = (int(vals[field]) * 30) - 2
                del vals[field]
            vals, done = self.magic_field(model, vals, company_id, attrs)
            if done:
                continue
            elif field == 'id':
                continue
            elif parent_id and attrs.get('relation') == parent_model:
                vals[field] = parent_id
                parent_name = field
            elif field == 'company_id':
                vals[field] = company_id
                continue
            elif (attrs['ttype'] in ('many2one', 'one2many', 'many2many')
                  and len(vals[field].split('.')) == 2):
                if attrs['ttype'] == 'many2one':
                    vals[field] = self.env_ref(vals[field])
                else:
                    vals[field] = [(6, 0, [self.env_ref(vals[field])])]
                continue
            elif attrs['ttype'] == 'boolean':
                vals[field] = os0.str2bool(vals[field], False)
            elif attrs['ttype'] == 'date':
                pass
            elif attrs['ttype'] == 'datetime':
                if vals[field].startswith('+'):
                    vals[field] = str(datetime.today() +
                                      timedelta(int(vals[field][1:])))
                elif vals[field].startswith('-'):
                    vals[field] = str(datetime.today() -
                                      timedelta(int(vals[field][1:])))
            elif attrs.get('relation'):
                self.setup_model_structure(attrs['relation'])
                value = self.get_domain_field(model,
                                              vals,
                                              company_id,
                                              field=field)
                if value:
                    vals[field] = value
                else:
                    del vals[field]

            if (field.ttype == 'many2one' and isinstance(vals[name], str)
                    and len(vals[name].split('.')) == 2):
                vals[name] = self.ref_id(vals[name])
        return vals
示例#7
0
def bind_fields(ctx, model, vals, company_id,
                parent_id=None, parent_model=None):
    setup_model_structure(ctx, model)
    parent_name = False
    for field in vals.copy():
        attrs = ctx['STRUCT'][model].get(field, {})
        if not attrs:
            print_error(ctx, 'Invalid field %s!' % field)
            if (model == 'account.payment.term.line' and
                    field == 'months' and
                    vals[field]):
                vals['days'] = (int(vals[field]) * 30) - 2
            del vals[field]
            continue
        if (model == 'account.account' and
                field == 'id' and
                vals[field].startswith('z0bug.')):
            xrefs = vals[field].split('.')
            ids = clodoo.searchL8(
                ctx, 'ir.model.data', [('module', '=', 'l10n_it_fiscal'),
                                       ('name', 'like', xrefs[1]),
                                       ('model', '=', 'account.account')])
            for xid in ids:
                xref = clodoo.browseL8(ctx, 'ir.model.data', xid)
                if xref and xref.name.endswith(xrefs[1]):
                    acc = clodoo.browseL8(ctx, model, xref.res_id)
                    if acc.company_id.id == company_id:
                        vals[field] = acc.id
                        break
            if 'user_type_id' in vals:
                if ctx['STRUCT'][model].get('nature', {}):
                    if isinstance(vals['user_type_id'], int):
                        acc = clodoo.browseL8(
                            ctx, 'account.account.type', vals['user_type_id'])
                    else:
                        acc = clodoo.browseL8(
                            ctx, 'account.account.type',
                            env_ref(ctx, vals['user_type_id']))
                    if acc.nature:
                        vals['nature'] = acc.nature
            continue
        elif model == 'account.payment.term.line' and field == 'option':
            if (vals[field] == 'fix_day_following_month' and
                    ctx['odoo_ver'] == '12.0'):
                vals[field] = 'day_following_month'
        elif field == 'id':
            continue
        elif parent_id and attrs.get('relation') == parent_model:
            vals[field] = parent_id
            parent_name = field
        elif field == 'company_id':
            vals[field] = company_id
            continue
        elif (attrs['ttype'] in (
                    'many2one', 'one2many', 'many2many') and
              len(os0.u(vals[field]).split('.')) == 2):
            vals[field] = env_ref(ctx, os0.u(vals[field]))
            continue
        elif attrs['ttype'] == 'boolean':
            vals[field] = os0.str2bool(vals[field], True)
        elif attrs['ttype'] == 'date':
            if vals[field].startswith('+'):
                vals[field] = str(
                    date.today() + timedelta(int(vals[field][1:])))
            elif vals[field].startswith('-'):
                vals[field] = str(
                    date.today() - timedelta(int(vals[field][1:])))
            elif vals[field].find('<#') >= 0:
                items = vals[field].split('-')
                for i, item in enumerate(items):
                    if item == '<#':
                        if i == 0:
                            items[i] = date.today().year - 1
                        elif i == 1:
                            items[i] = date.today().month - 1
                        elif i == 2:
                            items[i] = date.today().day - 1
                        if item[i] == 0:
                            item[i] = 1
                vals[field] = '%04d-%02d-%02d' % (
                    int(items[0]), int(items[1]), int(items[2]))
            elif vals[field].find('#>') >= 0:
                items = vals[field].split('-')
                for i, item in enumerate(items):
                    if item == '#>':
                        if i == 0:
                            items[i] = date.today().year + 1
                        elif i == 1:
                            items[i] = date.today().month + 1
                            if item[i] > 12:
                                item[i] = 12
                        elif i == 2:
                            items[i] = date.today().day + 1
                            if item[i] > 31:
                                item[i] = 31
                vals[field] = '%04d-%02d-%02d' % (
                    int(items[0]), int(items[1]), int(items[2]))
            elif vals[field].find('#') >= 0:
                items = vals[field].split('-')
                for i,item in enumerate(items):
                    if item == '#':
                        if i == 0:
                            items[i] = date.today().year
                        elif i == 1:
                            items[i] = date.today().month
                        elif i == 2:
                            items[i] = date.today().day
                vals[field] = '%04d-%02d-%02d' % (
                    int(items[0]), int(items[1]), int(items[2]))
        elif attrs['ttype'] == 'datetime':
            if vals[field].startswith('+'):
                vals[field] = str(
                    datetime.today() + timedelta(int(vals[field][1:])))
            elif vals[field].startswith('-'):
                vals[field] = str(
                    datetime.today() - timedelta(int(vals[field][1:])))
        elif attrs.get('relation'):
            setup_model_structure(ctx, attrs['relation'])
            value = get_domain_field(ctx, model, vals, company_id, field=field)
            if value:
                vals[field] = value
            else:
                del vals[field]
    if parent_id and parent_model:
        vals['id'] = get_domain_field(
            ctx, model, vals, company_id,
            parent_id=parent_id, parent_name=parent_name)
        if not vals['id']:
            del vals['id']
    if ctx['load_images'] and 'image' in ctx['STRUCT'][model]:
        file_image = os.path.join(
            os.path.dirname(__file__),
            'data',
            '%s.png' % vals['id'])
        if os.path.isfile(file_image):
            with open(file_image, 'rb') as fd:
                image = fd.read()
            vals['image'] = base64.b64encode(image)
    return vals, parent_name