def change_aml(po, dbo, uo, pod, du, dp, dpo, dh, fini, ffin):
    conect = oerplib.OERP('localhost', port=pod)
    conect.login(user=uo, passwd=po, database=dbo)
    conp = psycopg2.connect("dbname='{dn}' user='******' host='{dh}' "
                            "password='******' port={dpo}".format(dn=dbo,
                                                                du=du,
                                                                dh=dh,
                                                                dp=dp,
                                                                dpo=dpo))

    invoice_ids = conect.search('account.invoice',
                                [('date_invoice', '>=', fini),
                                 ('date_invoice', '<=', ffin)])

    invoice_line = conect.search('account.invoice.line',
                                 [('invoice_id', 'in', invoice_ids),
                                  ('move_id', '<>', False)])
    for inv_line in conect.browse('account.invoice.line', invoice_line):
        move_line = conect.search(
            'account.move.line',
            [('product_id', '=', inv_line.product_id.id),
             ('move_id', '=', inv_line.invoice_id.move_id.id),
             ('quantity', '=', inv_line.quantity)])
        list_browse_acc_move_lines2 = conect.browse('account.move.line',
                                                    move_line)
        for line in list_browse_acc_move_lines2:
            if line.account_id and line.account_id.reconcile:
                conect.write('account.move.line', line.id,
                             {'sm_id': inv_line.move_id.id})
    def authenticate(self, username=None, password=None):
        if not hasattr(self, "odoo_settings"):
            self.odoo_settings = OdooSettings()
        odoo = oerplib.OERP(self.odoo_settings.HOSTNAME, protocol=self.odoo_settings.PROTOCOL, port=self.odoo_settings.BINDPORT)

        try:
            user = odoo.login(username, password, self.odoo_settings.DATABASE)
        except OdooBackendException:
            return None
        except oerplib.error.RPCError:
            return None
        if (user.id):
            user_data = odoo.execute('res.users', 'read', [user.id])
            for gid in self.odoo_settings.GROUPFILTER:
                if (gid not in user_data[0]['groups_id']):
                    #print "GID: " + str(gid) + " not matched."
                    return None

            try:
                user = User.objects.get(username=user_data[0]['login'])
            except User.DoesNotExist:
                user = User(username=user_data[0]['login'],
                            first_name=user_data[0]['name'].split()[0],
                            last_name=user_data[0]['name'].split()[-1],
                            email=user_data[0]['email'],
                            )
                user.set_unusable_password()
                user.save()
            
            return user
        else:
            return None
示例#3
0

        
示例#4
0
def main():
    # switching to german:
    locale.setlocale(locale.LC_ALL, "de_DE.UTF-8")
    reload(sys).setdefaultencoding('UTF-8')  # somehow doesn't work

    if (sys.stdout.encoding != "UTF-8"):
        print sys.stdout.encoding
        print >> sys.stderr, "please use a UTF-8 locale, e.g. LANG=en_US.UTF-8"
        exit(1)

    cfg = ConfigParser({
        'db_file': 'production.sqlite3',
        'request_backup': 'off',
        'cash': 'off',
        'cash_manual': 'off',
        'FAUcard': 'off',
        'invoice': 'off'
    })
    cfg.readfp(codecs.open('config.ini', 'r', 'utf8'))

    oerp = oerplib.OERP(server=cfg.get('openerp', 'server'),
                        protocol='xmlrpc+ssl',
                        database=cfg.get('openerp', 'database'),
                        port=cfg.getint('openerp', 'port'),
                        version=cfg.get('openerp', 'version'))
    user = oerp.login(user=cfg.get('openerp', 'user'),
                      passwd=cfg.get('openerp', 'password'))

    data = {}
    data = importProdukteOERP(data, oerp, cfg)
    outputdir = os.path.dirname(
        os.path.realpath(__file__)) + '/../../../produkte/'

    saveToDir(data, outputdir)
示例#5
0
    def _main_odoo_instance_connect(self, cr, uid, ids, context=None):

        _logger.info("--> _main_odoo_instance_connect <--")
        o2o_simple_config_settings = self.pool.get(
            'o2o_simple.config.settings').search(cr, uid, [])
        _logger.info("o2o_simple_config_settings =) " +
                     str(o2o_simple_config_settings))

        username = self.pool.get('ir.config_parameter').get_param(
            cr, uid, 'yo_o2o_username')
        password = self.pool.get('ir.config_parameter').get_param(
            cr, uid, 'yo_o2o_password')
        url = self.pool.get('ir.config_parameter').get_param(
            cr, uid, 'yo_o2o_url')
        port = self.pool.get('ir.config_parameter').get_param(
            cr, uid, 'yo_o2o_port')
        dbname = self.pool.get('ir.config_parameter').get_param(
            cr, uid, 'yo_o2o_dbname')
        default_dist_warehouse_id = self.pool.get(
            'ir.config_parameter').get_param(
                cr, uid, 'yo_o2o_default_dist_warehouse_id')
        default_product_internal_categ_id = self.pool.get(
            'ir.config_parameter').get_param(
                cr, uid, 'yo_o2o_default_product_internal_categ_id')
        default_dist_price_list_id = self.pool.get(
            'ir.config_parameter').get_param(
                cr, uid, 'yo_o2o_default_dist_price_list_id')

        settings = {
            'default_dist_warehouse_id': default_dist_warehouse_id,
            'default_product_internal_categ_id':
            default_product_internal_categ_id,
            'default_dist_price_list_id': default_dist_price_list_id
        }

        error = False

        #oerp = oerplib.OERP(url, protocol='xmlrpc', port=port)

        try:
            oerp = oerplib.OERP(url, protocol='xmlrpc', port=port)
        except:
            error = True
            _logger.error("Enable to connect Odoo main instance")
        # Check available databases
        #print(oerp.db.list())

        # Login (the object returned is a browsable record)
        if not error:
            user = oerp.login(username, password, dbname)
            #print(user.name)            # name of the user connected
            #print(user.company_id.name) # the name of its company

            # Simple 'raw' query
            user_data = oerp.execute('res.users', 'read', [user.id])
            #print(user_data)
        else:
            return False

        return {'OdooMainInstance': oerp, 'user': user, 'settings': settings}
示例#6
0
def connectL8(ctx):
    """Open connection to Odoo service"""
    try:
        if ctx['svc_protocol'] == 'jsonrpc':
            odoo = odoorpc.ODOO(ctx['db_host'], ctx['svc_protocol'],
                                ctx['xmlrpc_port'])
        else:
            odoo = oerplib.OERP(server=ctx['db_host'],
                                protocol=ctx['svc_protocol'],
                                port=ctx['xmlrpc_port'],
                                version=ctx['oe_version'])
    except BaseException:  # pragma: no cover
        return u"!Odoo server %s is not running!" % ctx['oe_version']
    if ctx['svc_protocol'] == 'jsonrpc':
        ctx['server_version'] = odoo.version
    else:
        try:
            ctx['server_version'] = odoo.db.server_version()
        except BaseException:
            ctx['server_version'] = odoo.version
    x = re.match(r'[0-9]+\.[0-9]+', ctx['server_version'])
    if ctx['server_version'][0:x.end()] != ctx['oe_version']:
        return u"!Invalid Odoo Server version: expected %s, found %s!" % \
            (ctx['oe_version'], ctx['server_version'])
    ctx['majver'] = int(ctx['server_version'].split('.')[0])
    ctx['odoo_session'] = odoo
    return True
示例#7
0
def get_oerp():
    oerp = oerplib.OERP(settings.OERP_HOST,
            protocol=getattr(settings,"OERP_PROTOCOL", DEFAULT_PROTOCOL),
            port=getattr(settings, "OERP_PORT", DEFAULT_PORT))
    oerp.login(settings.OERP_USER,
               settings.OERP_PASSWORD,
               settings.OERP_DATABASE)
    return oerp
示例#8
0
def connect_rpc(args, db):
    netrpc = oerplib.OERP('127.0.0.1',
                          protocol='xmlrpc',
                          port=8069,
                          timeout=1000,
                          version='6.0')
    netrpc.login(args.adminuser.lower(), args.adminpw, database=db)
    return netrpc
示例#9
0
 def setUp(self):
     self.oerp = oerplib.OERP(ARGS.server,
                              protocol=ARGS.protocol,
                              port=ARGS.port,
                              version=ARGS.version)
     self.user = self.oerp.login(ARGS.user, ARGS.passwd, ARGS.database)
     self.session_name = ARGS.database
     self.file_path = tempfile.mkstemp(suffix='.cfg', prefix='oerplib_')[1]
示例#10
0
 def db_list(self):
     """
     Query for the server database list.
     """
     self.server = oerplib.OERP(server=self.server,
                                protocol=self.protocol,
                                port=self.port)
     return oerp.db.list()
示例#11
0
def database_exists(database_name, super_user_pass, host, port):
    """
    Check if a given database exists

    :returns: True if database exists, False otherwise
    """
    logger.debug("Checking if database exists")
    oerp = oerplib.OERP(host, protocol='xmlrpc', port=port, timeout=3000)
    return oerp.db.db_exist(database_name)
示例#12
0
 def setUp(self):
     self.oerp = oerplib.OERP(ARGS.server,
                              protocol=ARGS.protocol,
                              port=ARGS.port,
                              version=ARGS.version)
     if v(self.oerp.version) < v('6.1'):
         raise unittest.SkipTest(
             "The targetted OpenERP server does not support the "
             "'execute_kw()' method.")
     self.user = self.oerp.login(ARGS.user, ARGS.passwd, ARGS.database)
示例#13
0
 def test_init1(self):
     # Server + Database + Protocol + Port
     oerp = oerplib.OERP(ARGS.server, ARGS.database, ARGS.protocol,
                         ARGS.port)
     self.assertIsInstance(oerp, oerplib.OERP)
     self.assertIsNotNone(oerp)
     self.assertEqual(oerp.server, ARGS.server)
     self.assertEqual(oerp.database, ARGS.database)
     self.assertEqual(oerp.protocol, ARGS.protocol)
     self.assertEqual(oerp.port, ARGS.port)
示例#14
0

        
示例#15
0
def dump_database(dest_folder, database_name, super_user_pass, host, port):
    """
    Dump database using Oerplib in Base64 format
    """
    logger.debug("Dumping database %s into %s folder", database_name, dest_folder)
    dump_name = os.path.join(DEST_FOLDER, 'database_dump.b64')
    oerp = oerplib.OERP(host, protocol='xmlrpc', port=port, timeout=3000)
    binary_data = oerp.db.dump(super_user_pass, database_name)
    with open(dump_name, "w") as fout:
        fout.write(binary_data)
    return dump_name
示例#16
0
def restore_database(dest_folder, database_name, super_user_pass, host, port):
    """
    Restore database using Oerplib in Base64 format
    """
    logger.info("Restoring database %s", database_name)
    dump_name = os.path.join(dest_folder, 'database_dump.b64')
    logger.debug("Restore dump - reading file %s", dump_name)
    with open(dump_name, "r") as fin:
        b64_str = fin.read()
    oerp = oerplib.OERP(host, protocol='xmlrpc', port=port, timeout=3000)
    oerp.db.restore(super_user_pass, database_name, b64_str)
示例#17
0
 def test_init2(self):
     # Server + Database + Protocol + Port + Timeout
     oerp = oerplib.OERP(ARGS.server, ARGS.database, ARGS.protocol,
                         ARGS.port, 42)
     self.assertIsInstance(oerp, oerplib.OERP)
     self.assertIsNotNone(oerp)
     self.assertEqual(oerp.server, ARGS.server)
     self.assertEqual(oerp.database, ARGS.database)
     self.assertEqual(oerp.protocol, ARGS.protocol)
     self.assertEqual(oerp.port, ARGS.port)
     self.assertEqual(oerp.config['timeout'], 42)
示例#18
0
文件: connector.py 项目: maljac/test
def get_odoo_api(hostname, port, database, protocol, username, password):
    """ Create a OERP instance for further reuse """
    # TODO(MJ): Switch to OdooRPC and test performance in load test
    api = oerplib.OERP(
        server=hostname,
        database=database,
        protocol='xmlrpc',  # jsonrpc is not implemented in oerplib
        port=port)
    api.login(username, password)
    _logger.info('Created a new Odoo API instance')
    return api
示例#19
0
文件: upd_oemod.py 项目: tate11/tools
def initialize_params(ctx):
    xml_port = 8069
    database = 'demo'
    user = '******'
    passwd = 'admin'
    oe_version = '7.0'
    write_config_file = False
    opt_config = ctx.get('opt_config', './inv2draft_n_restore.conf')
    try:
        fd = open(opt_config, 'r')
        lines = fd.read().split('\n')
        for line in lines:
            tkn = line.split('=')
            if tkn[0] == 'login_user':
                user = tkn[1]
            elif tkn[0] == 'login_password':
                passwd = tkn[1]
            elif tkn[0] == 'db_name':
                database = tkn[1]
            elif tkn[0] == 'xml_port':
                xml_port = int(tkn[1])
            elif tkn[0] == 'oe_version':
                oe_version = tkn[1]
        fd.close()
    except BaseException:
        write_config_file = True
        if ctx.get('opt_db', None) is None:
            database = raw_input('database[def=demo]? ')
        user = raw_input('username[def=admin]? ')
        passwd = raw_input('password[def=admin]? ')
        p = raw_input('port[def=8069]? ')
        if p:
            xml_port = int(p)
        if ctx.get('oe_version', None) is None:
            p = raw_input('odoo version[def=7.0]? ')
            if p:
                oe_version = p
    if ctx.get('opt_db', None) is not None:
        database = ctx['opt_db']
    if ctx.get('oe_version', None) is not None:
        oe_version = ctx['oe_version']
    oerp = oerplib.OERP(port=xml_port, version=oe_version)
    uid = oerp.login(user=user, passwd=passwd, database=database)
    if write_config_file:
        fd = open(opt_config, 'w')
        fd.write('login_user=%s\n' % user)
        fd.write('login_password=%s\n' % passwd)
        fd.write('db_name=%s\n' % database)
        if xml_port != 8069:
            fd.write('xml_port=%d\n' % xml_port)
        if oe_version:
            fd.write('oe_version=%s\n' % oe_version)
        fd.close()
    return oerp, uid
def change_aml(po, dbo, uo, pod, du, dp, dpo, dh):
    conect = oerplib.OERP('localhost', port=pod)
    conect.login(user=uo, passwd=po, database=dbo)
    conp = psycopg2.connect("dbname='{dn}' user='******' host='{dh}' "
                            "password='******' port={dpo}".format(dn=dbo,
                                                                du=du,
                                                                dh=dh,
                                                                dp=dp,
                                                                dpo=dpo))
    purchase_no_confirmed = conect.search('purchase.order',
                                          [('state', '=', 'draft')])
    print purchase_no_confirmed, "Purchase Open"
    conect.write('purchase.order', purchase_no_confirmed,
                 {'picking_type_id': 7})
示例#21
0
    def server_login(self, **kwargs):
        '''
        Create an oerplib obejct logged with logged with parameters obtained
        for this methos

         >>> from vauxootools import VauxooToolsServers
         >>> from instance import Instance
         >>> configuration = VauxooToolsServers(app_name='App Test',
         ...                  usage_message="Created by VauxooTools",
         ...                  options=['dbname', 'hostname', 'il', 'password',
         ...                           'port', 'sd', 'sh', 'spo', 'sp', 'su',
         ...                           'username'])

         configuration is a vauxootools object with all sent manage parameter

         >>> con = Instance(dbname='localhost', hostname='localhost',
         ...                port=8070, username='******',
         ...                logger=configuration.logger)

         >>> login = con.server_login(host='localhost', user='******',
         ...                          password='******',
         ...                          database='test_db', port=8070)

        @param host: String with the server location
        @param user: String with the user login
        @param password: String with the password for the sent user
        @param database: String with database name to get or set new records
        @param port: Integer with port to which the server works


        :raise: :class:`oerplib.error.RPCError`
        :return: a oerplib login object or False if any parameter is wrong
        '''

        con = oerplib.OERP(
            server=kwargs.get('host', False) or self.hostname,
            database=kwargs.get('database', False) or self.dbname,
            port=kwargs.get('port', False) or self.port,
            timeout=9999999)
        try:
            con.login(kwargs.get('user') or self.username, kwargs.get('password') or self.password)
            self.logger.info("Logged with user %s" % (kwargs.get('user') or self.username))
        except Exception, error:
            con = False
            self.logger.error("We can't do login in the iserver: "
                              "http://%s:%s with user %s" % \
                                      (kwargs.get('host') or self.hostname, kwargs.get('port') or self.port,
                                      kwargs.get('user') or self.username))
            self.logger.error(error)
示例#22
0
    def __init__(self,
                 name=None,
                 server='localhost',
                 port='8069',
                 user='******',
                 password='******'):
        """
        Create an instance of OdooServer class.

        Arguments:
        config_filename -- Full path to the server configuration file.
        """
        self.server = oerplib.OERP(server=server, protocol='xmlrpc', port=port)
        if name:
            self.user = self.server.login(user, password, name)
def change_aml(po, dbo, uo, pod, du, dp, dpo, dh):
    conect = oerplib.OERP('localhost', port=pod)
    conect.login(user=uo, passwd=po, database=dbo)
    conp = psycopg2.connect("dbname='{dn}' user='******' host='{dh}' "
                            "password='******' port={dpo}".format(dn=dbo,
                                                                du=du,
                                                                dh=dh,
                                                                dp=dp,
                                                                dpo=dpo))

    product_ids = conect.search('product.product',
                                [('valuation', '=', 'real_time')])
    move_ids = conect.search('stock.move', [('product_id', 'in', product_ids),
                                            ('picking_id', '!=', False),
                                            ('state', '=', 'done')])
    pick_ids = []
    file_new = open('/tmp/moves_changeds.csv', 'wb')
    file_new.write('id, name, date, period\n')
    for move in conect.read('stock.move', move_ids, ['date', 'picking_id']):
        if move.get('picking_id')[0] in pick_ids:
            continue
        else:
            pick_ids.append(move.get('picking_id')[0])
        date_move = datetime.datetime.strptime(str(
            move.get('date')), '%Y-%m-%d %H:%M:%S').date().strftime('%Y-%m-%d')
        account_period_obj = conect.get('account.period')
        period_date = account_period_obj.find(dt=date_move, context={})
        acc_m_ids = conect.search('account.move',
                                  [('ref', '=', move.get('picking_id')[1]),
                                   ('period_id', '!=', period_date[0])])
        for acc_mv in conect.browse('account.move', acc_m_ids):
            cr = conp.cursor()
            cr.execute("""UPDATE account_move
                          SET period_id={pid}, date='{dte}'
                          WHERE id={amid}""".format(pid=period_date[0],
                                                    dte=date_move,
                                                    amid=acc_mv.id))
            for line in acc_mv.line_id:
                cr.execute("""UPDATE account_move_line
                          SET period_id={pid}, date='{dte}'
                          WHERE id={amlid}""".format(pid=period_date[0],
                                                     dte=date_move,
                                                     amlid=line.id))
            file_new.write('%s, %s, %s, %s\n' %
                           (acc_mv.id, acc_mv.name, acc_mv.date,
                            acc_mv.period_id.id or ''))
    file_new.close()
    conp.commit()
示例#24
0
文件: db.py 项目: lermit4/ufload
def connect_instance_to_sync_server(args, sync_server, db):
    #Temporary desactivation of auto-connect
    #return 0

    # if db.startswith('SYNC_SERVER'):
    #    return 0

    #oerp = oerplib.OERP('127.0.0.1', protocol='xmlrpc', port=12173, version='6.0')
    ufload.progress('Connecting instance %s to %s' % (db, sync_server))
    #netrpc = oerplib.OERP('127.0.0.1', protocol='xmlrpc', port=12173, timeout=1000, version='6.0')
    netrpc = oerplib.OERP('127.0.0.1', protocol='xmlrpc', port=8069, timeout=1000, version='6.0')
    netrpc.login(args.adminuser.lower(), args.adminpw, database=db)
    conn_manager = netrpc.get('sync.client.sync_server_connection')
    conn_ids = conn_manager.search([])
    conn_manager.write(conn_ids, {'password': args.adminpw})
    conn_manager.connect()