コード例 #1
0
 def setUp(self):
     super(TestReconcile, self).setUp()
     tools.convert_file(
         self.cr, 'account',
         get_module_resource('account', 'test', 'account_minimal_test.xml'),
         {}, 'init', False, 'test')
     self.rec_history_obj = self.env['mass.reconcile.history']
     self.mass_rec_obj = self.env['account.mass.reconcile']
     self.mass_rec_method_obj = (self.env['account.mass.reconcile.method'])
     self.mass_rec = self.mass_rec_obj.create({
         'name':
         'AER2',
         'account':
         self.ref('account.a_salary_expense'),
     })
     self.mass_rec_method = self.mass_rec_method_obj.create({
         'name':
         'mass.reconcile.simple.name',
         'sequence':
         '10',
         'task_id':
         self.mass_rec.id,
     })
     self.mass_rec_no_history = self.mass_rec_obj.create({
         'name':
         'AER3',
         'account':
         self.ref('account.a_salary_expense'),
     })
     self.rec_history = self.rec_history_obj.create({
         'mass_reconcile_id':
         self.mass_rec.id,
         'date':
         fields.Datetime.now(),
     })
コード例 #2
0
def post_init(cr, registry):
    """Import CSV data as it is faster than xml and because we can't use
    noupdate anymore with csv"""
    from openerp.tools import convert_file
    filename = 'data/res.bank.csv'
    convert_file(cr, 'l10n_ch_bank', filename, None, mode='init',
                 noupdate=True, kind='init', report=None)
    def setUp(self):
        super(TestScenarioReconcile, self).setUp()
        tools.convert_file(self.cr, 'account',
                           get_module_resource('account', 'test',
                                               'account_minimal_test.xml'),
                           {}, 'init', False, 'test')
        self.rec_history_obj = self.env['mass.reconcile.history']
        self.mass_rec_obj = self.env['account.mass.reconcile']
        self.invoice_obj = self.env['account.invoice']
        self.bk_stmt_obj = self.env['account.bank.statement']
        self.bk_stmt_line_obj = self.env['account.bank.statement.line']
        self.acc_move_line_obj = self.env['account.move.line']
        self.mass_rec_method_obj = (
            self.env['account.mass.reconcile.method']
        )
        self.account_fx_income_id = self.ref("account.income_fx_income")
        self.account_fx_expense_id = self.ref("account.income_fx_expense")
        self.acs_model = self.env['account.config.settings']

        acs_ids = self.acs_model.search(
            [('company_id', '=', self.ref("base.main_company"))]
            )

        values = {'group_multi_currency': True,
                  'currency_id': self.ref('base.EUR')}

        if acs_ids:
            acs_ids.write(values)
        else:
            default_vals = self.acs_model.default_get([])
            default_vals.update(values)
            acs_ids = self.acs_model.create(default_vals)
コード例 #4
0
ファイル: loading.py プロジェクト: sohaibrafiq/tweaks
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """
        try:
            if kind in ('demo', 'test'):
                threading.currentThread().testing = True
            for filename in _get_files_of_kind(kind):
                _logger.info("loading %s/%s", module_name, filename)
                noupdate = False
                if kind in ('demo', 'demo_xml') or (filename.endswith('.csv') and kind in ('init', 'init_xml')):
                    noupdate = True
            if tools.config.options.get('noupdate_if_unchanged'):
                cr.execute('select value from ir_values where name=%s and key=%s', (pathname, 'digest'))
                olddigest = (cr.fetchone() or (None,))[0]
                if olddigest is None:
                    cr.execute('insert into ir_values (name, model, key, value) values (%s, %s, %s, NULL)',
                               (pathname, 'ir_module_module', 'digest',))
                digest = md5.md5(fp.read()).hexdigest()
                fp.seek(0)
                if digest == olddigest:
                    noupdate = True
                else:
                    cr.execute('update ir_values set value=%s where name=%s and key=%s', (digest, pathname, 'digest'))        
                tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
        finally:
            if kind in ('demo', 'test'):
                threading.currentThread().testing = False
コード例 #5
0
    def setUp(self):
        super(TestScenarioReconcile, self).setUp()
        tools.convert_file(
            self.cr, 'account',
            get_module_resource('account', 'test', 'account_minimal_test.xml'),
            {}, 'init', False, 'test')
        self.rec_history_obj = self.env['mass.reconcile.history']
        self.mass_rec_obj = self.env['account.mass.reconcile']
        self.invoice_obj = self.env['account.invoice']
        self.bk_stmt_obj = self.env['account.bank.statement']
        self.bk_stmt_line_obj = self.env['account.bank.statement.line']
        self.acc_move_line_obj = self.env['account.move.line']
        self.mass_rec_method_obj = (self.env['account.mass.reconcile.method'])
        self.account_fx_income_id = self.ref("account.income_fx_income")
        self.account_fx_expense_id = self.ref("account.income_fx_expense")
        self.acs_model = self.env['account.config.settings']

        acs_ids = self.acs_model.search([('company_id', '=',
                                          self.ref("base.main_company"))])

        values = {
            'group_multi_currency': True,
            'currency_id': self.ref('base.EUR')
        }

        if acs_ids:
            acs_ids.write(values)
        else:
            default_vals = self.acs_model.default_get([])
            default_vals.update(values)
            acs_ids = self.acs_model.create(default_vals)
コード例 #6
0
ファイル: ir_module.py プロジェクト: sarahosay/cft
        def _load_data(cr, module_name, idref, mode, kind):
            """

            kind: data, demo, test, init_xml, update_xml, demo_xml.

            noupdate is False, unless it is demo data or it is csv data in
            init mode.

            """
            try:
                if kind in ('demo', 'test'):
                    threading.currentThread().testing = True
                for filename in _get_files_of_kind(kind):
                    _logger.info("loading %s/%s", module_name, filename)
                    noupdate = False
                    if kind in ('demo',
                                'demo_xml') or (filename.endswith('.csv') and
                                                kind in ('init', 'init_xml')):
                        noupdate = True
                    tools.convert_file(cr, module_name, filename, idref, mode,
                                       noupdate, kind,
                                       registry._assertion_report)
            finally:
                if kind in ('demo', 'test'):
                    threading.currentThread().testing = False
コード例 #7
0
ファイル: ir_module.py プロジェクト: LCCERP/erp-updated
    def import_module(self, cr, uid, module, path, force=False, context=None):
        known_mods = self.browse(cr, uid, self.search(cr, uid, []))
        known_mods_names = dict([(m.name, m) for m in known_mods])
        installed_mods = [m.name for m in known_mods if m.state == 'installed']

        terp = openerp.modules.load_information_from_description_file(module, mod_path=path)
        values = self.get_values_from_terp(terp)

        unmet_dependencies = set(terp['depends']).difference(installed_mods)
        if unmet_dependencies:
            msg = _("Unmet module dependencies: %s")
            raise osv.except_osv(_('Error !'), msg % ', '.join(unmet_dependencies))

        mod = known_mods_names.get(module)
        if mod:
            self.write(cr, uid, mod.id, dict(state='installed', **values))
            mode = 'update' if not force else 'init'
        else:
            assert terp.get('installable', True), "Module not installable"
            self.create(cr, uid, dict(name=module, state='installed', **values))
            mode = 'init'

        for kind in ['data', 'init_xml', 'update_xml']:
            for filename in terp[kind]:
                _logger.info("module %s: loading %s", module, filename)
                noupdate = False
                if filename.endswith('.csv') and kind in ('init', 'init_xml'):
                    noupdate = True
                pathname = opj(path, filename)
                idref = {}
                convert_file(cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname)

        path_static = opj(path, 'static')
        ir_attach = self.pool['ir.attachment']
        if os.path.isdir(path_static):
            for root, dirs, files in os.walk(path_static):
                for static_file in files:
                    full_path = opj(root, static_file)
                    with open(full_path, 'r') as fp:
                        data = fp.read().encode('base64')
                    url_path = '/%s%s' % (module, full_path.split(path)[1].replace(os.path.sep, '/'))
                    url_path = url_path.decode(sys.getfilesystemencoding())
                    filename = os.path.split(url_path)[1]
                    values = dict(
                        name=filename,
                        datas_fname=filename,
                        url=url_path,
                        res_model='ir.ui.view',
                        type='binary',
                        datas=data,
                    )
                    att_id = ir_attach.search(cr, uid, [('url', '=', url_path), ('type', '=', 'binary'), ('res_model', '=', 'ir.ui.view')], context=context)
                    if att_id:
                        ir_attach.write(cr, uid, att_id, values, context=context)
                    else:
                        ir_attach.create(cr, uid, values, context=context)

        return True
コード例 #8
0
 def setUp(self):
     super(BaseCompletion, self).setUp()
     tools.convert_file(
         self.cr, 'account',
         get_module_resource('account', 'test', 'account_minimal_test.xml'),
         {}, 'init', False, 'test')
     self.account_move_obj = self.env["account.move"]
     self.account_move_line_obj = \
         self.env["account.move.line"]
     self.company_a = self.browse_ref('base.main_company')
     self.journal = self.browse_ref("account.bank_journal")
     self.partner = self.browse_ref("base.res_partner_12")
     self.account_id = self.ref("account.a_recv")
コード例 #9
0
ファイル: loading.py プロジェクト: splbio/openobject-server
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """
        for filename in _get_files_of_kind(kind):
            _logger.info("module %s: loading %s", module_name, filename)
            noupdate = False
            if kind in ('demo', 'demo_xml') or (filename.endswith('.csv') and kind in ('init', 'init_xml')):
                noupdate = True
            tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
コード例 #10
0
 def setUp(self):
     super(PermanentLock, self).setUp()
     tools.convert_file(
         self.cr, 'account',
         get_module_resource('account', 'test', 'account_minimal_test.xml'),
         {}, 'init', False, 'test')
     self.account_move_obj = self.env["account.move"]
     self.account_move_line_obj = \
         self.env["account.move.line"]
     self.company_id = self.ref('base.main_company')
     self.partner = self.browse_ref("base.res_partner_12")
     self.account_id = self.ref("account.a_recv")
     self.account_id2 = self.ref("account.a_expense")
     self.journal_id = self.ref("account.bank_journal")
     self.wizard_obj = self.env["permanent.lock.date.wizard"]
コード例 #11
0
 def setUp(self):
     super(TestOnChange, self).setUp()
     tools.convert_file(self.cr, 'account',
                        get_module_resource('account', 'test',
                                            'account_minimal_test.xml'),
                        {}, 'init', False, 'test')
     acc_setting = self.env['account.config.settings']
     self.acc_setting_obj = acc_setting.create({})
     self.company_obj = self.env['res.company']
     # analytic defaults account creation
     self.main_company = self.env.ref('base.main_company')
     self.sec_company = self.company_obj.create(
         {
             'name': 'Second company',
             'reconciliation_commit_every': 80
         }
     )
コード例 #12
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """
        try:
            if kind in ('demo', 'test'):
                threading.currentThread().testing = True
            for filename in _get_files_of_kind(kind):
                _logger.info("loading %s/%s", module_name, filename)
                noupdate = False
                if kind in ('demo',
                            'demo_xml') or (filename.endswith('.csv')
                                            and kind in ('init', 'init_xml')):
                    noupdate = True
            if tools.config.options.get('noupdate_if_unchanged'):
                cr.execute(
                    'select value from ir_values where name=%s and key=%s',
                    (pathname, 'digest'))
                olddigest = (cr.fetchone() or (None, ))[0]
                if olddigest is None:
                    cr.execute(
                        'insert into ir_values (name, model, key, value) values (%s, %s, %s, NULL)',
                        (
                            pathname,
                            'ir_module_module',
                            'digest',
                        ))
                digest = md5.md5(fp.read()).hexdigest()
                fp.seek(0)
                if digest == olddigest:
                    noupdate = True
                else:
                    cr.execute(
                        'update ir_values set value=%s where name=%s and key=%s',
                        (digest, pathname, 'digest'))
                tools.convert_file(cr, module_name, filename, idref, mode,
                                   noupdate, kind, report)
        finally:
            if kind in ('demo', 'test'):
                threading.currentThread().testing = False
コード例 #13
0
 def setUp(self):
     super(PermanentLock, self).setUp()
     tools.convert_file(
         self.cr,
         "account",
         get_module_resource("account", "test", "account_minimal_test.xml"),
         {},
         "init",
         False,
         "test",
     )
     self.account_move_obj = self.env["account.move"]
     self.account_move_line_obj = self.env["account.move.line"]
     self.company_id = self.ref("base.main_company")
     self.partner = self.browse_ref("base.res_partner_12")
     self.account_id = self.ref("account.a_recv")
     self.account_id2 = self.ref("account.a_expense")
     self.journal_id = self.ref("account.bank_journal")
     self.wizard_obj = self.env["permanent.lock.date.wizard"]
コード例 #14
0
 def setUp(self):
     super(TestReconcileHistory, self).setUp()
     tools.convert_file(
         self.cr, 'account',
         get_module_resource('account', 'test', 'account_minimal_test.xml'),
         {}, 'init', False, 'test')
     self.rec_history_obj = self.env['mass.reconcile.history']
     self.mass_rec_obj = self.env['account.mass.reconcile']
     self.mass_rec = self.mass_rec_obj.create({
         'name':
         'AER1',
         'account':
         self.ref('account.a_expense'),
     })
     self.rec_history = self.rec_history_obj.create({
         'mass_reconcile_id':
         self.mass_rec.id,
         'date':
         fields.Datetime.now(),
     })
コード例 #15
0
    def setUp(self):
        super(BankAccountCompletion, self).setUp()
        tools.convert_file(
            self.cr, 'account',
            get_module_resource('account', 'test', 'account_minimal_test.xml'),
            {}, 'init', False, 'test')
        self.account_move_obj = self.env["account.move"]
        self.account_move_line_obj = \
            self.env["account.move.line"].with_context(
                check_move_validity=False
            )
        self.company_a = self.browse_ref('base.main_company')
        self.completion_rule_id = \
            self.ref('account_move_bankaccount_import.'
                     'bank_statement_completion_rule_10')
        self.journal = self.browse_ref("account.bank_journal")
        self.partner = self.browse_ref('base.main_partner')
        self.account_id = self.ref("account.a_recv")

        # Create the profile
        self.journal.write({
            'used_for_completion': True,
            'rule_ids': [(6, 0, [self.completion_rule_id])]
        })
        # Create a bank statement
        self.move = self.account_move_obj.create({
            "date": fields.Date.today(),
            "journal_id": self.journal.id
        })

        # Add a bank account number to the partner
        self.res_partner_bank_obj = self.env['res.partner.bank']
        vals = {
            "state": "bank",
            "company_id": self.company_a.id,
            "partner_id": self.partner.id,
            "acc_number": ACC_NUMBER,
            "footer": True,
            "bank_name": "Reserve",
        }
        self.partner_bank = self.res_partner_bank_obj.create(vals)
コード例 #16
0
ファイル: loading.py プロジェクト: glovebx/odoo
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """
        try:
            if kind in ("demo", "test"):
                threading.currentThread().testing = True
            for filename in _get_files_of_kind(kind):
                _logger.info("loading %s/%s", module_name, filename)
                noupdate = False
                if kind in ("demo", "demo_xml") or (filename.endswith(".csv") and kind in ("init", "init_xml")):
                    noupdate = True
                tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
        finally:
            if kind in ("demo", "test"):
                threading.currentThread().testing = False
コード例 #17
0
    def _reload(self, mod_name, model_name, ex_name, res_id):
        """ Private reload method which contains the real behavior to load
            each one of the views.
        """

        self._log(1, 'UPD', mod_name, ex_name)

        try:
            # STEP 1: Find XML file with given external ID
            xml_files = self._get_xml_files(mod_name, demo=False)
            xml_file = self._search_in_files(mod_name, xml_files, ex_name)

            # STEP 2: Call the update method
            convert_file(self.env.cr,
                         mod_name,
                         xml_file, {model_name: res_id},
                         mode='update',
                         noupdate=False,
                         kind='data')
        except Exception as ex:
            self._log(3, 'UPDFAIL', mod_name, ex_name, ex)
コード例 #18
0
    def setUp(self):
        super(TestReconcileHistory, self).setUp()
        tools.convert_file(self.cr, 'account',
                           get_module_resource('account', 'test',
                                               'account_minimal_test.xml'),
                           {}, 'init', False, 'test')
        self.rec_history_obj = self.env['mass.reconcile.history']
        self.mass_rec_obj = self.env['account.mass.reconcile']
        self.mass_rec = self.mass_rec_obj.create(
            {
                'name': 'AER1',
                'account': self.ref('account.a_expense'),

            }
            )
        self.rec_history = self.rec_history_obj.create(
            {
                'mass_reconcile_id': self.mass_rec.id,
                'date': fields.Datetime.now(),
            }
            )
コード例 #19
0
ファイル: ir_module.py プロジェクト: ecosoft-odoo/cft
        def _load_data(cr, module_name, idref, mode, kind):
            """

            kind: data, demo, test, init_xml, update_xml, demo_xml.

            noupdate is False, unless it is demo data or it is csv data in
            init mode.

            """
            try:
                if kind in ('demo', 'test'):
                    threading.currentThread().testing = True
                for filename in _get_files_of_kind(kind):
                    _logger.info("loading %s/%s", module_name, filename)
                    noupdate = False
                    if kind in ('demo', 'demo_xml') or (filename.endswith('.csv') and kind in ('init', 'init_xml')):
                        noupdate = True
                    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, registry._assertion_report)
            finally:
                if kind in ('demo', 'test'):
                    threading.currentThread().testing = False
コード例 #20
0
 def setUp(self):
     super(TestCodaImport, self).setUp()
     self.company_a = self.browse_ref('base.main_company')
     tools.convert_file(
         self.cr, 'account',
         get_module_resource('account', 'test', 'account_minimal_test.xml'),
         {}, 'init', False, 'test')
     self.account_move_obj = self.env["account.move"]
     self.account_move_line_obj = self.env["account.move.line"]
     self.account_id = self.ref("account.a_recv")
     self.journal = self.browse_ref("account.bank_journal")
     self.import_wizard_obj = self.env['credit.statement.import']
     self.partner = self.browse_ref("base.res_partner_12")
     self.journal.write({
         'used_for_import': True,
         "import_type": "generic_csvxls_so",
         'partner_id': self.partner.id,
         'commission_account_id': self.account_id,
         'receivable_account_id': self.account_id,
         'create_counterpart': True,
     })
コード例 #21
0
    def setUp(self):
        super(TestReconcile, self).setUp()
        tools.convert_file(self.cr, 'account',
                           get_module_resource('account', 'test',
                                               'account_minimal_test.xml'),
                           {}, 'init', False, 'test')
        self.rec_history_obj = self.env['mass.reconcile.history']
        self.mass_rec_obj = self.env['account.mass.reconcile']
        self.mass_rec_method_obj = (
            self.env['account.mass.reconcile.method']
        )
        self.mass_rec = self.mass_rec_obj.create(
            {
                'name': 'AER2',
                'account': self.ref('account.a_salary_expense'),
            }
            )
        self.mass_rec_method = self.mass_rec_method_obj.create(
            {
                'name': 'mass.reconcile.simple.name',
                'sequence': '10',
                'task_id': self.mass_rec.id,
            }
            )
        self.mass_rec_no_history = self.mass_rec_obj.create(
            {
                'name': 'AER3',
                'account': self.ref('account.a_salary_expense'),

            }
            )
        self.rec_history = self.rec_history_obj.create(
            {
                'mass_reconcile_id': self.mass_rec.id,
                'date': fields.Datetime.now(),
            }
            )
コード例 #22
0
    def _reload(self, mod_name, model_name, ex_name, res_id):
        """ Private reload method which contains the real behavior to load
            each one of the views.
        """

        self._log(1, 'UPD', mod_name, ex_name)

        try:
            # STEP 1: Find XML file with given external ID
            xml_files = self._get_xml_files(mod_name, demo=False)
            xml_file = self._search_in_files(mod_name, xml_files, ex_name)

            # STEP 2: Call the update method
            convert_file(
                self.env.cr,
                mod_name,
                xml_file,
                {model_name: res_id},
                mode='update',
                noupdate=False,
                kind='data'
            )
        except Exception as ex:
            self._log(3, 'UPDFAIL', mod_name, ex_name, ex)
コード例 #23
0
ファイル: ir_module.py プロジェクト: jssuzanne/odoo-foodcoops
    def import_module(self, cr, uid, module, path, force=False, context=None):
        known_mods = self.browse(cr, uid, self.search(cr, uid, []))
        known_mods_names = dict([(m.name, m) for m in known_mods])
        installed_mods = [m.name for m in known_mods if m.state == 'installed']

        terp = openerp.modules.load_information_from_description_file(
            module, mod_path=path)
        values = self.get_values_from_terp(terp)

        unmet_dependencies = set(terp['depends']).difference(installed_mods)
        if unmet_dependencies:
            msg = _("Unmet module dependencies: %s")
            raise UserError(msg % ', '.join(unmet_dependencies))

        mod = known_mods_names.get(module)
        if mod:
            self.write(cr, uid, mod.id, dict(state='installed', **values))
            mode = 'update' if not force else 'init'
        else:
            assert terp.get('installable', True), "Module not installable"
            self.create(
                cr, uid,
                dict(name=module, state='installed', imported=True, **values))
            mode = 'init'

        for kind in ['data', 'init_xml', 'update_xml']:
            for filename in terp[kind]:
                ext = os.path.splitext(filename)[1].lower()
                if ext not in ('.xml', '.csv', '.sql'):
                    _logger.info("module %s: skip unsupported file %s", module,
                                 filename)
                    continue
                _logger.info("module %s: loading %s", module, filename)
                noupdate = False
                if filename.endswith('.csv') and kind in ('init', 'init_xml'):
                    noupdate = True
                pathname = opj(path, filename)
                idref = {}
                convert_file(cr,
                             module,
                             filename,
                             idref,
                             mode=mode,
                             noupdate=noupdate,
                             kind=kind,
                             pathname=pathname)

        path_static = opj(path, 'static')
        ir_attach = self.pool['ir.attachment']
        if os.path.isdir(path_static):
            for root, dirs, files in os.walk(path_static):
                for static_file in files:
                    full_path = opj(root, static_file)
                    with open(full_path, 'r') as fp:
                        data = fp.read().encode('base64')
                    url_path = '/%s%s' % (module,
                                          full_path.split(path)[1].replace(
                                              os.path.sep, '/'))
                    url_path = url_path.decode(sys.getfilesystemencoding())
                    filename = os.path.split(url_path)[1]
                    values = dict(
                        name=filename,
                        datas_fname=filename,
                        url=url_path,
                        res_model='ir.ui.view',
                        type='binary',
                        datas=data,
                    )
                    att_id = ir_attach.search(
                        cr,
                        uid, [('url', '=', url_path), ('type', '=', 'binary'),
                              ('res_model', '=', 'ir.ui.view')],
                        context=context)
                    if att_id:
                        ir_attach.write(cr,
                                        uid,
                                        att_id,
                                        values,
                                        context=context)
                    else:
                        ir_attach.create(cr, uid, values, context=context)

        return True
コード例 #24
0
 def _load(self, module, *args):
     tools.convert_file(self.cr, 'account_deferred_revenue',
                        get_module_resource(module, *args), {}, 'init',
                        False, 'test', self.registry._assertion_report)
コード例 #25
0
    def _load_data(cr, module_name, idref, mode, kind):
        """

        kind: data, demo, test, init_xml, update_xml, demo_xml.

        noupdate is False, unless it is demo data or it is csv data in
        init mode.

        """

        module_files = []
        module_modified = True
        if mode == 'update' and kind == 'data':
            cr.execute("select id from ir_module_module where name=%s",
                       (module_name, ))
            module_id = cr.fetchone()[0]
            for filename in _get_files_of_kind(kind):
                cr.execute(
                    "select id,checksum from ir_module_module_file"
                    " where module_id=%s and filename=%s",
                    (module_id, filename))
                checksum = cr.fetchone()
                module_file_id = checksum and checksum[0] or False
                checksum = checksum and checksum[1] or ''
                sha256 = hashlib.sha256()
                sha256.update(
                    misc.file_open(os.path.join(module_name, filename)).read())
                module_files += [{
                    'checksum': checksum,
                    'checksum_new': sha256.hexdigest(),
                    'module_file_id': module_file_id,
                    'module_id': module_id,
                    'filename': filename
                }]
            if len(module_files) == len([
                    1 for f in module_files
                    if f['checksum'] == f['checksum_new']
            ]):
                module_modified = bool(
                    tools.config.options.get('force_update', False))

        try:
            if kind in ('demo', 'test'):
                threading.currentThread().testing = True
            for filename in _get_files_of_kind(kind):
                _logger.info("%s %s/%s", module_modified and 'loading'
                             or 'no changes', module_name, filename)
                noupdate = False
                if kind in ('demo',
                            'demo_xml') or (filename.endswith('.csv')
                                            and kind in ('init', 'init_xml')):
                    noupdate = True
                if module_modified:
                    tools.convert_file(cr, module_name, filename, idref, mode,
                                       noupdate, kind, report)
        finally:
            if kind in ('demo', 'test'):
                threading.currentThread().testing = False

        if module_modified and mode == 'update' and kind == 'data':
            for module_file in [
                    f for f in module_files
                    if f['checksum'] != f['checksum_new']
            ]:
                if module_file['module_file_id']:
                    cr.execute(
                        "update ir_module_module_file set checksum=%s, write_date=now() where id=%s",
                        (module_file['checksum_new'],
                         module_file['module_file_id']))
                else:
                    cr.execute(
                        "insert into ir_module_module_file(filename,module_id,checksum,create_date,create_uid,write_date,write_uid)"
                        " values(%s,%s,%s,now(),1,now(),1)",
                        (module_file['filename'], module_file['module_id'],
                         module_file['checksum_new']))
        return module_modified
コード例 #26
0
ファイル: test_account_asset.py プロジェクト: DeltaComm/odoo
 def _load(self, module, *args):
     tools.convert_file(self.cr, 'account_asset',
                        get_module_resource(module, *args),
                        {}, 'init', False, 'test', self.registry._assertion_report)
コード例 #27
0
ファイル: ir_module.py プロジェクト: 2cadz/odoo
    def import_module(self, cr, uid, module, path, force=False, context=None):
        known_mods = self.browse(cr, uid, self.search(cr, uid, []))
        known_mods_names = dict([(m.name, m) for m in known_mods])
        installed_mods = [m.name for m in known_mods if m.state == "installed"]

        terp = openerp.modules.load_information_from_description_file(module, mod_path=path)
        values = self.get_values_from_terp(terp)

        unmet_dependencies = set(terp["depends"]).difference(installed_mods)
        if unmet_dependencies:
            msg = _("Unmet module dependencies: %s")
            raise UserError(msg % ", ".join(unmet_dependencies))

        mod = known_mods_names.get(module)
        if mod:
            self.write(cr, uid, mod.id, dict(state="installed", **values))
            mode = "update" if not force else "init"
        else:
            assert terp.get("installable", True), "Module not installable"
            self.create(cr, uid, dict(name=module, state="installed", **values))
            mode = "init"

        for kind in ["data", "init_xml", "update_xml"]:
            for filename in terp[kind]:
                _logger.info("module %s: loading %s", module, filename)
                noupdate = False
                if filename.endswith(".csv") and kind in ("init", "init_xml"):
                    noupdate = True
                pathname = opj(path, filename)
                idref = {}
                convert_file(cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, pathname=pathname)

        path_static = opj(path, "static")
        ir_attach = self.pool["ir.attachment"]
        if os.path.isdir(path_static):
            for root, dirs, files in os.walk(path_static):
                for static_file in files:
                    full_path = opj(root, static_file)
                    with open(full_path, "r") as fp:
                        data = fp.read().encode("base64")
                    url_path = "/%s%s" % (module, full_path.split(path)[1].replace(os.path.sep, "/"))
                    url_path = url_path.decode(sys.getfilesystemencoding())
                    filename = os.path.split(url_path)[1]
                    values = dict(
                        name=filename,
                        datas_fname=filename,
                        url=url_path,
                        res_model="ir.ui.view",
                        type="binary",
                        datas=data,
                    )
                    att_id = ir_attach.search(
                        cr,
                        uid,
                        [("url", "=", url_path), ("type", "=", "binary"), ("res_model", "=", "ir.ui.view")],
                        context=context,
                    )
                    if att_id:
                        ir_attach.write(cr, uid, att_id, values, context=context)
                    else:
                        ir_attach.create(cr, uid, values, context=context)

        return True
コード例 #28
0
def post_init(cr, registry):
# Import CSV data as it is faster than xml 
    from openerp.tools import convert_file
    convert_file(cr, 'systolicathemes_worldstates', 'data/res.country.state.csv', None, mode='init', noupdate=True,
                 kind='init', report=None)