Esempio n. 1
0
def get_company(ctx):
    model = 'res.company'
    ids = clodoo.searchL8(ctx, model, [('name', 'ilike', 'La Tua Azienda')])
    if not ids:
        ids = clodoo.searchL8(ctx, model, [('id', '>', 1)])
    if ids:
        return ids[0]
    else:
        return 1
Esempio n. 2
0
def get_company_id(ctx):
    model = 'res.company'
    company_name = ctx.get('company_name', 'La % Azienda')
    ids = clodoo.searchL8(ctx, model, [('name', 'ilike', company_name)])
    if not ids:
        ids = clodoo.searchL8(ctx, model, [('id', '>', 1)])
    if ids:
        return ids[0]
    else:
        return 1
Esempio n. 3
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
Esempio n. 4
0
def get_company_id(ctx):
    model = 'res.company'
    company_name = ctx.get('company_name', 'La % Azienda')
    ids = clodoo.searchL8(ctx, model, [('name', 'ilike', company_name)])
    if not ids:
        ids = clodoo.searchL8(ctx, model, [('id', '>', 1)])
    if ids:
        value = ids[0]
    else:
        value = 1
    if 'default_company_id' not in ctx:
        ctx['default_company_id'] = value
    return value
Esempio n. 5
0
def get_state_id(ctx, field_name, value, country_id):
    if value:
        x = 'IN_%s' % field_name
        model = 'res.country.state'
        if x == 'code':
            ids = clodoo.searchL8(ctx, model,
                                  [('country_id', '=', country_id),
                                   ('code', '=', value.upper())])
        else:
            ids = clodoo.searchL8(ctx, model,
                                  [('country_id', '=', country_id),
                                   ('name', 'ilike', value)])
        if ids:
            value = ids[0]
    return value
Esempio n. 6
0
def get_country_id(ctx, value):
    # country_code = False
    if value:
        model = 'res.country'
        if ctx.get('IN_country_id', '') == 'code':
            ids = clodoo.searchL8(ctx, model,
                                  [('code', '=', value.upper())])
        else:
            ids = clodoo.searchL8(ctx, model,
                                  [('name', 'ilike', value)])
        if ids:
            value = ids[0]
        if 'default_country_id' not in ctx:
            ctx['default_country_id'] = value
    return value
Esempio n. 7
0
def get_ids_from_params(model, company_id, P1=None, P2=None, P3=None):
    msg = "Dbg: search(%s [" % model
    if company_id:
        msg = msg + "(company_id, =, %s)," % company_id
    if P1:
        msg = msg + str(P1) + ','
    if P2:
        msg = msg + str(P2) + ','
    if P3:
        msg = msg + str(P3) + ','
    msg = msg + "]"
    print msg

    if P1 is False or P2 is False or P3 is False:
        return []
    where = []
    if company_id:
        where.append(('company_id', '=', company_id))
    if P1:
        where.append(P1)
    if P2:
        where.append(P2)
    if P3:
        where.append(P3)
    return clodoo.searchL8(ctx, model, where)
Esempio n. 8
0
def get_company_account(ctx):
    company_id = ctx['company_id']
    ids = clodoo.searchL8(ctx, 'account.account',
                          [('code', '=', '0'),
                           ('company_id', '=', company_id)])
    if len(ids) != 1:
        print "Company account not found!"
        sys.exit(1)
    return ids[0]
Esempio n. 9
0
def get_ids_from_name(model, company_id, target):
    where = []
    if company_id:
        where.append(('company_id', '=', company_id))
    if target.find('%') < 0:
        where.append(('name', '=', target))
    else:
        where.append(('name', 'like', target))
    return clodoo.searchL8(ctx, model, where)
Esempio n. 10
0
def get_code_values(ctx, code):
    model = 'account.account'
    company_id = ctx['company_id']
    vals = {}
    vals['code'] = code
    root_id = get_company_account(ctx)
    vals['parent_id'] = root_id
    vals['company_id'] = company_id
    vals['type'] = 'view'
    ids = clodoo.searchL8(ctx, 'account.account.type',
                          [('code', '=', 'view')])
    if len(ids) == 0:
        print "Type view not found!"
        sys.exit(1)
    vals['user_type'] = ids[0]
    if code == 'A':
        vals['name'] = 'ATTIVITÀ'
    elif code == 'P':
        vals['name'] = 'PASSIVITÀ'
    elif code == 'R':
        vals['name'] = 'RICAVI'
        ids = clodoo.searchL8(ctx, model, [('code', '=', '__'),
                                           ('company_id', '=', company_id)])
        if len(ids) != 1:
            print "L&P account not found!"
            sys.exit(1)
        vals['parent_id'] = ids[0]
    elif code == 'S':
        vals['name'] = 'COSTI'
        ids = clodoo.searchL8(ctx, model, [('code', '=', '__'),
                                           ('company_id', '=', company_id)])
        if len(ids) != 1:
            print "L&P account not found!"
            sys.exit(1)
        vals['parent_id'] = ids[0]
    elif code == '__':
        vals['name'] = 'UTILE (-) O PERDITA (+) DI ESERCIZIO'
    else:
        print "Invalid account code %s" % code
        sys.exit(1)
    return vals
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
0
 def drop_out_original_field(ctx, model, id, vals, name):
     do_ids = clodoo.searchL8(ctx, model, [(name, '=', vals[name])])
     if do_ids:
         for do_id in do_ids:
             if ctx['_cr']:
                 table = model.replace('.', '_')
                 sql = "update %s set %s='(id=%d) =>%d' where id=%d;" % (
                     table, name, do_id, id, do_id)
                 try:
                     ctx['_cr'].execute(sql)
                 except BaseException:
                     pass
             else:
                 try:
                     clodoo.writeL8(ctx, model, do_ids,
                                    {name: '(id=%d) =>%d' % (do_id, id)})
                 except BaseException:
                     pass
Esempio n. 14
0
            infos[item] = [
                os0.b(row[0]),
                os0.b(row[2]),
                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
            ]
Esempio n. 15
0
def upd_invoice(ctx, tmp_num=False, cur_num=False, cur_dt=False):
    move_name = get_name_by_ver(ctx, 'move_name')
    if not tmp_num and not cur_num:
        print ">> Missing parameters"
        return
    company_id = ctx['company_id']
    tmp_inv_id = False
    cur_inv_id = False
    if tmp_num:
        inv = clodoo.searchL8(ctx,
                              'account.invoice',
                              [('company_id', '=', company_id),
                               (move_name, '=', tmp_num)])
        if len(inv):
            tmp_inv_id = inv[0]
        else:
            return
        print ">>> tmp_inv=%d" % tmp_inv_id
    if cur_num:
        inv = clodoo.search(ctx,
                            'account.invoice',
                            [('company_id', '=', company_id),
                             (move_name, '=', cur_num)])
        if len(inv):
            cur_inv_id = inv[0]
        else:
            return
        print ">>> cur_inv=%d" % cur_inv_id
    if not tmp_inv_id and not cur_inv_id:
        print ">> No invoice found ", tmp_num, cur_num
        return
    if tmp_inv_id:
        rec_ids = [tmp_inv_id]
        tag = tmp_num
    else:
        rec_ids = [cur_inv_id]
        tag = cur_num
    print ">> Get info tmp invoice %s (%s)" % (str(rec_ids), tag)
    reconcile_dict, move_dict = clodoo.get_reconcile_from_invoices(
        rec_ids, ctx)
    print ">> Unreconcile tmp invoice"
    clodoo.unreconcile_invoices(reconcile_dict, ctx)
    if tmp_inv_id and cur_inv_id and tmp_inv_id != cur_inv_id:
        print ">> Delete tmp invoice"
        try:
            clodoo.writeL8(ctx,
                           'account.invoice',
                           tmp_inv_id,
                           {'state': 'cancel',
                            'number': '', move_name: ''})
        except BaseException:                                # pragma: no cover
            pass
        clodoo.unlinkL8(ctx, 'account.invoice', [tmp_inv_id])
    if cur_inv_id:
        rec_ids = [cur_inv_id]
        tag = cur_num
    else:
        rec_ids = [tmp_inv_id]
        tag = tmp_num
    if cur_inv_id and tmp_inv_id and tmp_inv_id != cur_inv_id:
        print ">> Get info cur invoice %s (%s)" % (str(rec_ids), tag)
        reconcile_dict, move_dict = clodoo.get_reconcile_from_invoices(
            rec_ids, ctx)
        print ">> Unreconcile cur invoices"
        clodoo.unreconcile_invoices(reconcile_dict, ctx)
    print ">> Draft cur invoices"
    clodoo.upd_invoices_2_draft(move_dict, ctx)
    inv_id = rec_ids[0]
    vals = {}
    if cur_dt:
        dt_s = str(cur_dt)
        period_ids = clodoo.executeL8(ctx, 'account.period', 'find', dt_s)
        period_id = period_ids and period_ids[0] or False
        vals['date_invoice'] = dt_s
        vals['registration_date'] = dt_s
        vals['period_id'] = period_id
    if cur_num and tmp_num and tmp_num != cur_num:
        vals[move_name] = tmp_num
    if len(vals):
        print ">> Update values ", inv_id, vals
        clodoo.writeL8(ctx, 'account.invoice', inv_id, vals)
    print ">> Posted"
    clodoo.upd_invoices_2_posted(move_dict, ctx)
    reconciles = reconcile_dict[inv_id]
    if len(reconciles):
        print ">> Reconcile "
        cur_reconciles, cur_reconcile_dict = clodoo.refresh_reconcile_from_inv(
            inv_id, reconciles, ctx)
        clodoo.reconcile_invoices(cur_reconcile_dict, ctx)
    return
Esempio n. 16
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
Esempio n. 17
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)


if __name__ == "__main__":
    # pdb.set_trace()
    oerp, uid, ctx = init_n_connect()
    print "Update Chart of Account on DB %s" % (ctx['db_name'])
    ids = clodoo.searchL8(ctx, 'res.company', [])
    for company_id in ids:
        ctx['company_id'] = company_id
        update_coa(ctx)
Esempio n. 18
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
Esempio n. 19
0
left_ctx['db_name'] = left_ctx['left_db_name']
left_ctx['conf_fn'] = left_ctx['left_conf_fn']
right_ctx['db_name'] = right_ctx['right_db_name']
right_ctx['conf_fn'] = right_ctx['right_conf_fn']
uid, right_ctx = clodoo.oerp_set_env(ctx=right_ctx)
uid, left_ctx = clodoo.oerp_set_env(ctx=left_ctx)
transodoo.read_stored_dict(right_ctx)
left_ctx['mindroot'] = right_ctx['mindroot']

for model in ('res.country.state', 'res.city', 'res.partner.bank'):
    copy_table(left_ctx, right_ctx, model)
for model in ('account.fiscal.position', 'res.partner'):
    copy_table(left_ctx, right_ctx, model)
for model in ('res.company', 'account.account.type', 'account.account'):
    copy_table(left_ctx, right_ctx, model)
for model in ('product.uom.categ', 'product.uom', 'product.category'):
    copy_table(left_ctx, right_ctx, model)
for model in (
        'product.template',
        'product.product',
):
    copy_table(left_ctx, right_ctx, model)
for model in ('account.tax', 'account.journal'):
    copy_table(left_ctx, right_ctx, model)
for model in ('account.invoice', 'account.invoice.line'):
    copy_table(left_ctx, right_ctx, model)

raw_input('Press RET to validate invoices ...')
ids = clodoo.searchL8(left_ctx, 'account.invoice', [('state', '=', 'draft')])
clodoo.upd_invoices_2_posted(ids, left_ctx)
Esempio n. 20
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
Esempio n. 21
0
         print_move_info(move_id)
         clodoo.executeL8(ctx, 'account.move',
                          "button_validate",
                          [move_id])
 elif action[0] == 'U':
     for move_id in rec_ids:
         print_move_info(move_id)
     print ">> Draft"
     clodoo.upd_payments_2_draft(rec_ids, ctx)
 elif action[0] == 'X':
     for move_id in rec_ids:
         print_move_info(move_id)
         inv_obj = clodoo.browseL8(ctx, MODEL['MH'], move_id)
         ref = inv_obj.ref
         moves = clodoo.searchL8(ctx,
                                 MODEL['MD'],
                                 [('move_id', '=', move_id)])
         clodoo.write(ctx, MODEL['MD'], moves,
                      {'ref': ref})
 if action[0] == 'X' or (action[0] != 'B' and
                         action != 'RB' and action[1] != '+'):
     continue
 res = raw_input('Press RET to restore status ..')
 if action[0] == 'P':
     print ">> Draft"
     clodoo.upd_payments_2_draft(rec_ids, ctx)
 elif action[0] == 'U':
     print ">> Posted"
     clodoo.upd_payments_2_posted(rec_ids, ctx)
 else:
     for inv_id in rec_ids: