def reset_unit_testing(self, **kwargs): # Keep a reference on the previous function previous_safe_eval = odoo_convert.safe_eval # Define a local context and override default `safe_eval` local_ctx = { 'same_hardware_identifier': 'SAME', 'other_hardware_identifier': 'OTHER', } # Let the testing user update local context with data from json local_ctx.update(request.params.copy()) odoo_convert.safe_eval = lambda expr, ctx={}: odoo_convert.s_eval( expr, ctx, local_ctx, nocopy=True) try: for file in [ 'data/unit_testing_software_license_application.xml', 'data/unit_testing_software_license.xml', ]: odoo_convert.convert_file(request.env.cr, 'software_license_portal', file, {}, mode='init', kind='data') finally: # Restore previous function odoo_convert.safe_eval = previous_safe_eval
def scenario_convert_file(cr, module, filename, idref, mode='update', noupdate=False, kind=None, report=None, pathname=None): if pathname is None: pathname = os.path.join(module, filename) directory, filename = os.path.split(pathname) extension = os.path.splitext(filename)[1].lower() if extension == '.scenario': fp = misc.file_open(pathname) try: with odoo.api.Environment.manage(): uid = odoo.SUPERUSER_ID env = odoo.api.Environment(cr, uid, {'active_test': False}) import_scenario(env, module, fp.read(), mode, directory, filename) finally: fp.close() else: convert_file(cr, module, filename, idref, mode=mode, noupdate=noupdate, kind=kind, report=report, pathname=pathname)
def load_onboarding_data(self): convert.convert_file(request.env.cr, 'point_of_sale', 'data/point_of_sale_onboarding.xml', None, mode='init', kind='data')
def create_imd(self, filename, kind, rows_expected=None, msgs_expected=None, module=None): """Create ir.model.data record from `convert_file` method. :param filename str: File name to import. :param kind str: Category of information (data, demo, test) :param rows_expected int: Number of records expected. :param msgs_expected int: Number of logger messages expected. :param module str: Name of module to import filename. default MODULE :return: ir.model.data browse with records created. """ if module is None: module = MODULE imd_before = self.imd.search([('module', '=', module)]) convert.convert_file(self.cr, module, filename, None, kind=kind) imd_after = self.imd.search([('module', '=', module)]) imd_new = (imd_after - imd_before) if rows_expected is not None: # TODO: Why locally I see rows_expected but # travis rows_expected + 1 self.assertTrue(len(imd_new) in [rows_expected + 1, rows_expected]) if msgs_expected is not None: logs = self.get_logs() self.assertEqual(len(logs), msgs_expected) return imd_new
def test_wrong_parent_scenario(self): """ Should raise if the parent scenario is not found """ with self.assertRaises(ValueError): convert_file( self.env.cr, 'stock_scanner', 'tests/data/TestWrongParent.scenario', {}, )
def test_wrong_company(self): """ Should raise if the company is not found """ with self.assertRaises(ValueError): convert_file( self.env.cr, 'stock_scanner', 'tests/data/TestWrongCompany.scenario', {}, )
def update_xml_record(self, xml_id, vals, path=None): """Update record that can be referenced via xml_id using vals. Args: xml_id (str): XML ID to reference record. vals (dict): values to update record with. path (str): record's definition file path. If specified, will try to load it in case XML ID does not exist. (default: {None}) Returns: updated record. """ def update(): record = self.env.ref(xml_id) record.write(vals) return record def get_module_and_filename(): # Assuming valid relative odoo path to module. module = path.split('/')[0] filename = os.path.basename(path) return module, filename try: return update() except ValueError: if path: module, filename = get_module_and_filename() # Load record's file. convert_file(self._cr, module, filename, {}, mode='init', pathname=path) # Try again. return update() else: raise
def install_addenda(self): """Helper to load addendas. Look for inside files data/*.xml inside with the name on the selection field, then import such xml as addenda view in order to have them as data inside odoo itself return view_id""" self.ensure_one() addenda = self.l10n_mx_addenda if not addenda: return {} addendas = join(get_module_path('l10n_mx_edi_addendas'), 'data') availables = listdir(addendas) addenda_fname = '.'.join([addenda, 'xml']) if addenda_fname not in availables: return pathname = join(addendas, addenda_fname) convert_file(self._cr, 'l10n_mx_edi_addendas', pathname, {}, pathname=pathname)