Ejemplo n.º 1
0
def update_coa(ctx):
    company_id = ctx['company_id']
    model = 'account.account'
    if len(clodoo.searchL8(ctx, model,
                           [('company_id', '=', company_id)])) < 100:
        return
    company = clodoo.browseL8(ctx, 'res.company', company_id)
    print "- Processing company %s" % company.name
    for code in ('__', 'A', 'P', 'R', 'S'):
        ids = clodoo.searchL8(ctx, model, [('code', '=', code),
                                           ('company_id', '=', company_id)])
        if len(ids) > 2:
            print "Warning: invalid account '%s'" % code
            sys.exit(1)
        elif ids:
            vals = get_code_values(ctx, code)
            try:
                clodoo.writeL8(ctx, model, ids[0], vals)
            except BaseException:
                pass
        else:
            vals = get_code_values(ctx, code)
            clodoo.createL8(ctx, model, vals)
    aprs = {}
    for code in ('__', 'A', 'P', 'R', 'S'):
        ids = clodoo.searchL8(ctx, model, [('code', '=', code),
                                           ('company_id', '=', company_id)])
        aprs[code] = ids[0]
    root_id = get_company_account(ctx)
    account_ids = clodoo.searchL8(ctx, model,
                                  [('type', '=', 'view'),
                                   ('parent_id', '=', root_id),
                                   ('id', 'not in', aprs.values())])
    for account_id in account_ids:
        ids = clodoo.searchL8(ctx, model, [('parent_id', '=', account_id)])
        if ids:
            account = clodoo.browseL8(ctx, model, ids[0])
            while account.type == 'view':
                ids = clodoo.searchL8(ctx, model, [('parent_id', '=', ids[0])])
                if ids:
                    account = clodoo.browseL8(ctx, model, ids[0])
                else:
                    account.type = 'asset'
            if account.user_type.code in ('asset', 'bank',
                                          'cash', 'receivable'):
                parent_id = aprs['A']
            elif account.user_type.code in ('equity', 'liability',
                                            'payable', 'tax'):
                parent_id = aprs['P']
            elif account.user_type.code == 'income':
                parent_id = aprs['R']
            elif account.user_type.code == 'expense':
                parent_id = aprs['S']
            else:
                parent_id = False
            if parent_id:
                vals = {}
                vals['parent_id'] = parent_id
                clodoo.writeL8(ctx, model, account_id, vals)
Ejemplo n.º 2
0
def get_symbolic_value(ctx, model, name, value):
    name_model = 'ir.model.data'
    field_model = 'ir.model.fields'
    if name:
        cache_name = '%s.%s.%s' % (model, name, value)
        if cache_name in CACHE:
            return CACHE[cache_name]
        field_id = clodoo.searchL8(ctx,
                                   field_model,
                                   [('model', '=', model),
                                    ('name', '=', name)])
        if field_id:
            relation = clodoo.browseL8(ctx,
                                       field_model,
                                       field_id[0]).relation
            name_id = clodoo.searchL8(ctx,
                                      name_model,
                                      [('model', '=', relation),
                                       ('res_id', '=', value)])
            if name_id:
                model_rec = clodoo.browseL8(ctx,
                                            name_model,
                                            name_id[0])
                value = '%s.%s' % (model_rec.module, model_rec.name)
                CACHE[cache_name] = value
            elif ctx['enhanced']:
                if name == 'company_id':
                    value = '=${company_id}'
                else:
                    for sel_name in ('code', 'name'):
                        ids = clodoo.searchL8(ctx,
                                              field_model,
                                              [('model', '=', relation),
                                               ('name', '=', sel_name)])
                        if ids:
                            break
                    if ids:
                        value = clodoo.browseL8(ctx,
                                                relation,
                                                value)[sel_name]
                        value = '=${%s(%s)::%s}' % (relation,
                                                    sel_name,
                                                    value)
    else:
        name_id = clodoo.searchL8(ctx,
                                  name_model,
                                  [('model', '=', model),
                                   ('res_id', '=', value)])
        if name_id:
            model_rec = clodoo.browseL8(ctx,
                                        name_model,
                                        name_id[0])
            value = '%s.%s' % (model_rec.module, model_rec.name)
    return value
Ejemplo n.º 3
0
def print_move_info(inv_id):
    model = 'account.move'
    inv_obj = clodoo.browseL8(ctx, model, inv_id)
    print "Id=%d, name=%s cid=%d" % (
        inv_id,
        inv_obj.name,
        inv_obj.company_id)
Ejemplo n.º 4
0
def print_invoice_info(inv_id):
    model = 'account.invoice'
    try:
        inv_obj = clodoo.browseL8(ctx, model, inv_id)
        print "Id=%d, Num=%s(%s), supply n.=%s, ref=%s cid=%d" % (
            inv_id,
            inv_obj.number,
            inv_obj.internal_number,
            inv_obj.supplier_invoice_number,
            inv_obj.name,
            inv_obj.company_id)
    except BaseException:
        print "Record not found!"
Ejemplo n.º 5
0
def copy_table(left_ctx, right_ctx, model):
    dummy = raw_input('Copy table %s (Y,n)? ' % model)
    if dummy == 'n' or dummy == 'N':
        return
    clodoo.declare_mandatory_fields(left_ctx, model)
    if right_ctx['_cr']:
        table = model.replace('.', '_')
        sql = 'select max(id) from %s;' % table
        right_ctx['_cr'].execute(sql)
        rows = right_ctx['_cr'].fetchall()
        last_id = rows[0][0]
        if last_id > 0:
            for id in clodoo.searchL8(left_ctx, model, [('id', '>', last_id)]):
                try:
                    clodoo.unlinkL8(left_ctx, model, id)
                except BaseException:
                    print "Cannot delete record %d of %s" % (id, model)
                    dummy = raw_input('Press RET to continue')
    where = []
    if model == 'res.lang':
        where = [('id', '>', 1)]
    elif model == 'res.partner':
        where = [('parent_id', '=', False)]
    for rec in clodoo.browseL8(
            right_ctx, model,
            clodoo.searchL8(right_ctx, model, where, order='id')):
        vals = clodoo.extract_vals_from_rec(right_ctx, model, rec)
        vals = clodoo.cvt_from_ver_2_ver(left_ctx, model,
                                         right_ctx['oe_version'],
                                         left_ctx['oe_version'], vals)
        msg_burst('%s %d' % (model, rec.id))
        ids = clodoo.searchL8(left_ctx, model, [('id', '=', rec.id)])
        if ids:
            write_no_dup(left_ctx, model, ids, vals, rec.id)
        else:
            create_with_id(left_ctx, model, rec.id, vals)
Ejemplo n.º 6
0
def export_table(ctx):
    current_year = date.today().year
    model = ctx['model']
    # name_model = 'ir.model.data'
    # field_model = 'ir.model.fields'
    out_file = ctx['out_file']
    if not out_file:
        out_file = model.replace('.', '_') + '.csv'
    print "Output file %s" % out_file
    csv_out = open(out_file, 'wb')
    hdr_file = model.replace('.', '_') + '.hdr' + out_file[-4:]
    hdr_file = os.path.join('./hdrs', hdr_file)
    try:
        hdr_fd = open(hdr_file, 'rbU')
        line = hdr_fd.read()
        hdr_fd.close()
        out_flds = line.split('\n')[0].split(',')
    except BaseException:
        print 'Header file %s not found!' % hdr_file
        return
    header = dict((n, n) for n in out_flds)
    csv_obj = csv.DictWriter(csv_out, fieldnames=out_flds)
    csv_obj.writerow(header)
    ctr = 0
    where = eval(ctx.get('search_where', []))
    for rec in clodoo.browseL8(ctx,
                               model,
                               clodoo.searchL8(ctx, model, where)):
        print 'Reading id %d' % rec.id
        out_dict = {}
        data_valid = True
        discard = False
        for nm in out_flds:
            f = nm.split(':')
            if nm == 'id':
                value = rec[f[0]]
                value = get_symbolic_value(ctx, model, False, value)
                if isinstance(value, (int, long)):
                    data_valid = False
                    if not re.match(ctx['id_filter'], str(value)):
                        discard = True
                        break
                else:
                    if not re.match(ctx['id_filter'], value):
                        discard = True
                        break
                    elif ctx['onlybase'] and value[0:5] != 'base.':
                        data_valid = False
                    elif ctx['exclmulti'] and value[0:5] == 'multi':
                        data_valid = False
            elif len(f) == 1:
                value = rec[f[0]]
                if isinstance(rec[f[0]], (date, datetime)):
                    ttype = clodoo.browseL8(
                        ctx, 'ir.model.fields', clodoo.searchL8(
                            ctx,
                            'ir.model.fields',
                            [('model', '=', model),
                             ('name', '=', f[0])])[0]).ttype
                    if ttype == 'date':
                        if value.year == current_year:
                            value = '${_current_year}-%02d-%02d' % (
                                value.month, value.day)
                        elif value.year == (current_year - 1):
                            value = '${_last_year}-%02d-%02d' % (value.month,
                                                                 value.day)
            elif f[1] == 'id':
                if isinstance(rec[f[0]], bool):
                    value = rec[f[0]]
                    if not value:
                        value = ''
                else:
                    try:
                        value = rec[f[0]][f[1]]
                    except BaseException:
                        value = ''
                    value = get_symbolic_value(ctx, model, f[0], value)
                if isinstance(value, (int, long)):
                    data_valid = False
                elif ctx['exclmulti'] and value[0:5] == 'multi':
                    data_valid = False
            if isinstance(value, (bool, int, float, long, complex)):
                out_dict[nm] = str(value)
            elif isinstance(value, basestring):
                out_dict[nm] = os0.b(value.replace('\n', ' '))
            else:
                out_dict[nm] = value
        if not discard and (not ctx['exclext'] or data_valid):
            csv_obj.writerow(out_dict)
            ctr += 1
    csv_out.close()
    print '%d record exported' % ctr
Ejemplo n.º 7
0
def add_elem(row, ctx, MYDICT):
    def cvt_val(ctx, field_name, value):
        x = 'trx_%s' % field_name
        if x in ctx:
            trx_dict = ctx[x]
            if value in trx_dict:
                value = trx_dict[value]
            else:
                value = value.strip()
        elif field_name == 'company_id':
            value = get_company_id(ctx)
        else:
            value = value.strip()
        return value

    def add_val(row, ctx, MYDICT, field_name):
        def_field_name = 'default_%s' % field_name
        if field_name in MYDICT:
            idx = MYDICT[field_name]
            if idx >= len(row):
                print 'Invalid translation field %d' % idx
                return
            vals[field_name] = cvt_val(ctx, field_name, row[idx])
        elif def_field_name in ctx:
            vals[field_name] = ctx[def_field_name]

    msg_burst('Reading %s ...' % row[MYDICT['name']])
    model = 'product.product'
    vals = {}
    add_val(row, ctx, MYDICT, 'name')
    for field_id in clodoo.searchL8(ctx, 'ir.model.fields',
                                    [('model', '=', model)]):
        field_name = clodoo.browseL8(ctx, 'ir.model.fields', field_id).name
        add_val(row, ctx, MYDICT, field_name)

    if 'name' not in vals:
        vals['name'] = 'PRODUCT'
    if 'company_id' not in vals:
        vals['company_id'] = get_company_id(ctx)

    ids = []
    if vals.get('code'):
        ids = clodoo.searchL8(ctx, model,
                              [('default_code', '=', vals['code'])])
    if not ids and vals.get('default_code'):
        ids = clodoo.searchL8(ctx, model,
                              [('default_code', '=', vals['default_code'])])
    if not ids:
        ids = clodoo.searchL8(ctx, model, [('name', '=', vals['name'])])
    if ids:
        product_id = ids[0]
        try:
            clodoo.writeL8(ctx, model, [product_id], vals)
        except BaseException:
            write_log("Cannot import %s" % vals['name'])
            try:
                clodoo.writeL8(ctx, model, [product_id], vals)
            except BaseException:
                pass
    else:
        try:
            product_id = clodoo.createL8(ctx, model, vals)
        except BaseException:
            write_log("Cannot create %s" % vals['name'])
            try:
                product_id = clodoo.createL8(ctx, model, vals)
            except BaseException:
                pass
Ejemplo n.º 8
0
def add_elem(row, ctx, MYDICT_C, MYDICT_S):
    def add_val(row, ctx, MYDICT, field_name):
        def_field_name = 'default_%s' % field_name
        if field_name in MYDICT:
            idx = MYDICT[field_name]
            if idx >= len(row):
                print 'Invalid translation field %d' % idx
                # continue
            vals[field_name] = cvt_val(ctx, field_name, row[idx])
            # if field_name == 'state_id':
            #     if row[idx]:
            #         state_id = row[idx]
        elif def_field_name in ctx:
            vals[field_name] = ctx[def_field_name]

    if ctx['customers']:
        MYDICT = MYDICT_C
    else:
        MYDICT = MYDICT_S
    msg_burst('Reading %s ...' % row[MYDICT['name']])
    ids = clodoo.searchL8(ctx, 'res.country',
                          [('code', '=', 'IT')])
    if ids:
        country_IT = ids[0]
    model = 'res.partner'
    vals = {}
    country_code = False
    state_id = False
    for field_id in clodoo.searchL8(ctx, 'ir.model.fields',
                                    [('model', '=', model)]):
        field_name = clodoo.browseL8(ctx, 'ir.model.fields', field_id).name
        add_val(row, ctx, MYDICT, field_name)

    if 'is_company' not in vals:
        vals['is_company'] = True
    if 'name' not in vals:
        vals['name'] = 'UNKNOWN'
    elif 'name2' in MYDICT:
        vals['name'] = '%s %s' % (vals['name'], row[MYDICT['name2']])
        vals['name'] = vals['name'].strip()
    if 'company_id' not in vals:
        vals['company_id'] = get_company_id(ctx)
    if 'country_id' not in vals:
        vals['country_id'] = country_IT
        country_code = 'IT'
    if state_id:
        if ctx.get('IN_state_id') == 'code':
            ids = clodoo.searchL8(ctx, 'res.country.state',
                                  [('country_id', '=', vals['country_id']),
                                   ('code', '=', state_id.upper())])
        else:
            ids = clodoo.searchL8(ctx, 'res.country.state',
                                  [('country_id', '=', vals['country_id']),
                                   ('name', 'ilike', state_id)])
        if ids:
            vals['state_id'] = ids[0]
    if vals.get('vat'):
        if country_code and country_code != vals['vat'][0:2]:
            if country_code == 'IT' and vals['vat'].isdigit():
                vals['vat'] = 'IT%011d' % int(vals['vat'])
            else:
                vals['vat'] = country_code + vals['vat']

    if country_code in ('AT', 'BE', 'BG', 'CY', 'HR', 'DK',
                        'EE', 'FI', 'FR', 'DE', 'GB', 'EL', 'IE',
                        'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT',
                        'CZ', 'SK', 'RO', 'SI', 'ES', 'SE', 'HU'):
        fiscal = 'Regime%UE'
    elif country_code and country_code != 'IT':
        fiscal = 'Extra%UE'
    else:
        fiscal = 'Italia'
    ids = clodoo.searchL8(ctx, 'account.fiscal.position',
                          [('company_id', '=', vals['company_id']),
                           ('name', 'ilike', fiscal)])
    if ids:
        vals['propert_account_position'] = ids[0]

    ids = []
    if vals.get('old_customer_id'):
        ids = clodoo.searchL8(ctx, model, [('old_customer_id',
                                            '=',
                                            vals['old_customer_id'])])
    if not ids and vals.get('old_supplier_id'):
        ids = clodoo.searchL8(ctx, model, [('old_supplier_id',
                                            '=',
                                            vals['old_supplier_id'])])
    if not ids and vals.get('vat'):
        ids = clodoo.searchL8(ctx, model, [('vat', '=', vals['vat'])])
    if not ids:
        ids = clodoo.searchL8(ctx, model, [('name', '=', vals['name'])])
    if not ids:
        vals['customer'] = False
        vals['supplier'] = False
    if ctx['customers']:
        vals['customer'] = True
    if ctx['suppliers']:
        vals['supplier'] = True
    if ids:
        partner_id = ids[0]
        try:
            clodoo.writeL8(ctx, model, [partner_id], vals)
        except BaseException:
            write_log("Cannot import %s" % vals['name'])
            if vals.get('vat'):
                del vals['vat']
            try:
                clodoo.writeL8(ctx, model, [partner_id], vals)
            except BaseException:
                pass
    else:
        try:
            partner_id = clodoo.createL8(ctx, model, vals)
        except BaseException:
            write_log("Cannot create %s" % vals['name'])
            if vals.get('vat'):
                del vals['vat']
            try:
                partner_id = clodoo.createL8(ctx, model, vals)
            except BaseException:
                pass
Ejemplo n.º 9
0
                os0.b(row[4]),
                os0.b(row[3]),
                os0.b(row[5]), ''
            ]
            add_elem(mod2xtl, '0', item)

if ctx['db_name']:
    uid, ctx = clodoo.oerp_set_env(confn=ctx['conf_fn'],
                                   db=ctx['db_name'],
                                   ctx=ctx)
    ixver = ctx['oe_version'].split('.')[0] + ctx['oe_version'].split('.')[1]
    model = 'ir.module.module'
    ids = clodoo.searchL8(ctx, model, [('state', '=', 'installed')])
    for id in ids:
        try:
            module = clodoo.browseL8(ctx, model, id)
            item = module.name
            if item in infos:
                notes = infos[item][2]
                summary = get_summary(infos[item][0])
            else:
                notes = ''
                summary = get_summary(os0.b(module.summary))
            infos[item] = [
                summary,
                os0.b(module.author), notes,
                os0.b(module.installed_version), '', ixver
            ]
        except BaseException:
            pass
with open('moduli_alias.csv', 'rb') as f:
Ejemplo n.º 10
0
     if action[0] != 'N' and actsrc in STSNAME['draft']:
         sts2s.append(STSNAME['draft'][actsrc])
     if len(sts2s):
         P3 = ('state', 'not in', sts2s)
 elif actsrc in STSNAME['draft']:
     P3 = ('state', '=', STSNAME['draft'][actsrc])
 if search_mode in (':A:', ':C:'):
     dtl_ids = get_ids_from_params(model_dtl,
                                   company_id,
                                   P1=P1,
                                   P2=P2,
                                   P3=P3)
     hdr_ids = []
     for id in dtl_ids:
         if invmov == 'M':
             idd = clodoo.browseL8(ctx, model_dtl, id).move_id.id
         else:
             idd = clodoo.browseL8(ctx, model_dtl, id).invoice_id.id
         if idd not in hdr_ids:
             hdr_ids.append(idd)
     if len(hdr_ids):
         P1 = set_where_int('id', hdr_ids)
         P2 = set_where_int('period_id', period_ids)
         P3 = None
         if action[0] == 'S' and invmov == 'I':
             P3 = set_where_int('x_payment_status',
                                inv_status,
                                condnot=True)
         elif action[0] in ('P', 'U', 'V', 'X'):
             actsrc = actsrc[0] + 'H'
             if actsrc in STSNAME['draft']: