def test_ods_success(self): ods_file_path = get_module_resource('base_import', 'tests', 'test.ods') file_content = open(ods_file_path, 'rb').read() import_wizard = self.env['base_import.import'].create({ 'res_model': 'base_import.tests.models.preview', 'file': file_content, 'file_type': 'application/vnd.oasis.opendocument.spreadsheet' }) result = import_wizard.parse_preview({ 'headers': True, }) self.assertIsNone(result.get('error')) self.assertEqual(result['matches'], {0: ['name'], 1: ['somevalue'], 2: None}) self.assertEqual(result['headers'], ['name', 'Some Value', 'Counter']) self.assertItemsEqual(result['fields'], [ ID_FIELD, {'id': 'name', 'name': 'name', 'string': 'Name', 'required': False, 'fields': [], 'type': 'char'}, {'id': 'somevalue', 'name': 'somevalue', 'string': 'Some Value', 'required': True, 'fields': [], 'type': 'integer'}, {'id': 'othervalue', 'name': 'othervalue', 'string': 'Other Variable', 'required': False, 'fields': [], 'type': 'integer'}, ]) self.assertEqual(result['preview'], [ ['foo', '1', '2'], ['bar', '3', '4'], ['aux', '5', '6'], ]) # Ensure we only have the response fields we expect self.assertItemsEqual(list(result), ['matches', 'headers', 'fields', 'preview', 'headers_type', 'options', 'advanced_mode', 'debug'])
def test_crm_lead_message(self): # Give the access rights of Salesman to communicate with customer # Customer interested in our product, so he sends request by email to get more details. # Mail script will fetch his request from mail server. Then I process that mail after read EML file. request_file = open(get_module_resource('crm', 'tests', 'customer_request.eml'), 'rb') request_message = request_file.read() self.env['mail.thread'].sudo(self.crm_salesman).message_process('crm.lead', request_message) # After getting the mail, I check details of new lead of that customer lead = self.env['crm.lead'].sudo(self.crm_salesman).search([('email_from', '=', 'Mr. John Right <*****@*****.**>')], limit=1) self.assertTrue(lead.ids, 'Fail to create merge opportunity wizard') self.assertFalse(lead.partner_id, 'Customer should be a new one') self.assertEqual(lead.name, 'Fournir votre devis avec le meilleur prix.', 'Subject does not match') # I reply his request with welcome message. # TODO revert mail.mail to mail.compose.message (conversion to customer should be automatic). lead = self.env['crm.lead'].search([('email_from', '=', 'Mr. John Right <*****@*****.**>')], limit=1) mail = self.env['mail.compose.message'].with_context(active_model='crm.lead', active_id=lead.id).create({ 'body': "Merci de votre intérêt pour notre produit, nous vous contacterons bientôt. Bien à vous", 'email_from': '*****@*****.**' }) try: mail.send_mail() except: pass # Now, I convert him into customer and put him into regular customer list lead = self.env['crm.lead'].search([('email_from', '=', 'Mr. John Right <*****@*****.**>')], limit=1) lead.handle_partner_assignation()
def setUp(self): super().setUp() file_path = get_module_resource('base', 'tests', 'minimal.pdf') self.file = open(file_path, 'rb').read() self.minimal_reader_buffer = io.BytesIO(self.file) self.minimal_pdf_reader = pdf.FlectraPdfFileReader( self.minimal_reader_buffer)
def test_00_recruitment_process(self): """ Test recruitment process """ # Create a new HR Recruitment Officer self.res_users_hr_recruitment_officer = self.env['res.users'].create({ 'company_id': self.env.ref('base.main_company').id, 'name': 'HR Recruitment Officer', 'login': "******", 'email': "*****@*****.**", 'groups_id': [(6, 0, [self.env.ref('hr_recruitment.group_hr_recruitment_user').id])] }) # An applicant is interested in the job position. So he sends a resume by email. # In Order to test process of Recruitment so giving HR officer's rights with open(get_module_resource('hr_recruitment', 'tests', 'resume.eml'), 'rb') as request_file: request_message = request_file.read() self.env['mail.thread'].sudo( self.res_users_hr_recruitment_officer.id).message_process( 'hr.applicant', request_message, custom_values={"job_id": self.env.ref('hr.job_developer').id}) # After getting the mail, I check the details of the new applicant. applicant = self.env['hr.applicant'].search( [('email_from', '=', 'Mr. Richard Anderson <*****@*****.**>')], limit=1) self.assertTrue(applicant, "Applicant is not created after getting the mail") resume_ids = self.env['ir.attachment'].search([ ('datas_fname', '=', 'resume.pdf'), ('res_model', '=', self.env['hr.applicant']._name), ('res_id', '=', applicant.id) ]) self.assertEquals( applicant.name, 'Application for the post of Jr.application Programmer.', 'Applicant name does not match.') self.assertEquals( applicant.stage_id, self.env.ref('hr_recruitment.stage_job1'), "Stage should be 'Initial qualification' and is '%s'." % (applicant.stage_id.name)) self.assertTrue(resume_ids, 'Resume is not attached.') # I assign the Job position to the applicant applicant.write({'job_id': self.env.ref('hr.job_developer').id}) # I schedule meeting with applicant for interview. applicant_meeting = applicant.action_makeMeeting() self.assertEquals( applicant_meeting['context']['default_name'], 'Application for the post of Jr.application Programmer.', 'Applicant name does not match.')
def test_xlsx_success(self): xlsx_file_path = get_module_resource('base_import', 'tests', 'test.xlsx') file_content = open(xlsx_file_path, 'rb').read() import_wizard = self.env['base_import.import'].create({ 'res_model': 'base_import.tests.models.preview', 'file': file_content, 'file_type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) result = import_wizard.parse_preview({ 'headers': True, }) self.assertIsNone(result.get('error')) self.assertEqual(result['matches'], { 0: ['name'], 1: ['somevalue'], 2: None }) self.assertEqual(result['headers'], ['name', 'Some Value', 'Counter']) self.assertItemsEqual(result['fields'], [ ID_FIELD, { 'id': 'name', 'name': 'name', 'string': 'Name', 'required': False, 'fields': [], 'type': 'char' }, { 'id': 'somevalue', 'name': 'somevalue', 'string': 'Some Value', 'required': True, 'fields': [], 'type': 'integer' }, { 'id': 'othervalue', 'name': 'othervalue', 'string': 'Other Variable', 'required': False, 'fields': [], 'type': 'integer' }, ]) self.assertEqual(result['preview'], [ ['foo', '1', '2'], ['bar', '3', '4'], ['qux', '5', '6'], ])
def _load(cls, module, *args): convert_file( cls.cr, "dms", get_module_resource(module, *args), {}, "init", False, "test", cls.registry._assertion_report, )
def update_invoice_from_file(self, module_name, subfolder, filename, invoice): file_path = get_module_resource(module_name, subfolder, filename) file = open(file_path, 'rb').read() attachment = self.env['ir.attachment'].create({ 'name': filename, 'datas': base64.encodebytes(file), 'res_id': invoice.id, 'res_model': 'account.move', }) invoice.message_post(attachment_ids=[attachment.id])
def create_invoice_from_file(self, module_name, subfolder, filename): file_path = get_module_resource(module_name, subfolder, filename) file = open(file_path, 'rb').read() attachment = self.env['ir.attachment'].create({ 'name': filename, 'datas': base64.encodebytes(file), 'res_model': 'account.move', }) journal_id = self.company_data['default_journal_sale'] action_vals = journal_id.with_context( default_move_type='in_invoice').create_invoice_from_attachment( attachment.ids) return self.env['account.move'].browse(action_vals['res_id'])
def service_worker(self): """ Returns a ServiceWorker javascript file scoped for website_event """ sw_file = get_module_resource('website_event_track', 'static/src/js/service_worker.js') with open(sw_file, 'r') as fp: body = fp.read() js_cdn_url = 'undefined' if request.website.cdn_activated: cdn_url = request.website.cdn_url.replace('"', '%22').replace( '\x5c', '%5C') js_cdn_url = '"%s"' % cdn_url body = body.replace('__FLECTRA_CDN_URL__', js_cdn_url) response = request.make_response(body, [ ('Content-Type', 'text/javascript'), ('Service-Worker-Allowed', url_for('/event')), ]) return response
def _get_sample_sales_order(self): """ Get a sample quotation or create one if it does not exist. """ # use current user as partner partner = self.env.user.partner_id company_id = self.env.company.id # is there already one? sample_sales_order = self.env['sale.order'].search( [('company_id', '=', company_id), ('partner_id', '=', partner.id), ('state', '=', 'draft')], limit=1) if len(sample_sales_order) == 0: sample_sales_order = self.env['sale.order'].create( {'partner_id': partner.id}) # take any existing product or create one product = self.env['product.product'].search([], limit=1) if len(product) == 0: default_image_path = get_module_resource( 'product', 'static/img', 'product_product_13-image.png') product = self.env['product.product'].create({ 'name': _('Sample Product'), 'active': False, 'image_1920': base64.b64encode(open(default_image_path, 'rb').read()) }) product.product_tmpl_id.write({'active': False}) self.env['sale.order.line'].create({ 'name': _('Sample Order Line'), 'product_id': product.id, 'product_uom_qty': 10, 'price_unit': 123, 'order_id': sample_sales_order.id, 'company_id': sample_sales_order.company_id.id, }) return sample_sales_order
def _load(self, module, *args): tools.convert_file( self.cr, 'hr_payroll_account', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def setUp(self): super(TestUICommon, self).setUp() # Load pdf and img contents pdf_path = get_module_resource('website_slides', 'static', 'src', 'img', 'presentation.pdf') pdf_content = base64.b64encode(open(pdf_path, "rb").read()) img_path = get_module_resource('website_slides', 'static', 'src', 'img', 'slide_demo_gardening_1.jpg') img_content = base64.b64encode(open(img_path, "rb").read()) self.env['slide.channel'].create({ 'name': 'Basics of Gardening - Test', 'user_id': self.env.ref('base.user_admin').id, 'enroll': 'public', 'channel_type': 'training', 'allow_comment': True, 'promote_strategy': 'most_voted', 'is_published': True, 'description': 'Learn the basics of gardening !', 'create_date': Datetime.now() - relativedelta(days=8), 'slide_ids': [(0, 0, { 'name': 'Gardening: The Know-How', 'sequence': 1, 'datas': pdf_content, 'slide_type': 'presentation', 'is_published': True, 'is_preview': True, }), (0, 0, { 'name': 'Home Gardening', 'sequence': 2, 'image_1920': img_content, 'slide_type': 'infographic', 'is_published': True, }), (0, 0, { 'name': 'Mighty Carrots', 'sequence': 3, 'image_1920': img_content, 'slide_type': 'infographic', 'is_published': True, }), (0, 0, { 'name': 'How to Grow and Harvest The Best Strawberries | Basics', 'sequence': 4, 'datas': pdf_content, 'slide_type': 'document', 'is_published': True, }), (0, 0, { 'name': 'Test your knowledge', 'sequence': 5, 'slide_type': 'quiz', 'is_published': True, 'question_ids': [ (0, 0, { 'question': 'What is a strawberry ?', 'answer_ids': [ (0, 0, { 'text_value': 'A fruit', 'is_correct': True, 'sequence': 1, }), (0, 0, { 'text_value': 'A vegetable', 'sequence': 2, }), (0, 0, { 'text_value': 'A table', 'sequence': 3, }) ] }), (0, 0, { 'question': 'What is the best tool to dig a hole for your plants ?', 'answer_ids': [(0, 0, { 'text_value': 'A shovel', 'is_correct': True, 'sequence': 1, }), (0, 0, { 'text_value': 'A spoon', 'sequence': 2, })] }) ] })] })
def setUpClass(cls): super().setUpClass() # Setup attributes and attributes values cls.product_attribute_1 = cls.env['product.attribute'].create({ 'name': 'Legs', 'sequence': 10, }) product_attribute_value_1 = cls.env['product.attribute.value'].create({ 'name': 'Steel', 'attribute_id': cls.product_attribute_1.id, 'sequence': 1, }) product_attribute_value_2 = cls.env['product.attribute.value'].create({ 'name': 'Aluminium', 'attribute_id': cls.product_attribute_1.id, 'sequence': 2, }) product_attribute_2 = cls.env['product.attribute'].create({ 'name': 'Color', 'sequence': 20, }) product_attribute_value_3 = cls.env['product.attribute.value'].create({ 'name': 'White', 'attribute_id': product_attribute_2.id, 'sequence': 1, }) product_attribute_value_4 = cls.env['product.attribute.value'].create({ 'name': 'Black', 'attribute_id': product_attribute_2.id, 'sequence': 2, }) # Create product template cls.product_product_custo_desk = cls.env['product.template'].create({ 'name': 'Customizable Desk (TEST)', 'standard_price': 500.0, 'list_price': 750.0, }) # Generate variants cls.env['product.template.attribute.line'].create([{ 'product_tmpl_id': cls.product_product_custo_desk.id, 'attribute_id': cls.product_attribute_1.id, 'value_ids': [(4, product_attribute_value_1.id), (4, product_attribute_value_2.id)], }, { 'product_tmpl_id': cls.product_product_custo_desk.id, 'attribute_id': product_attribute_2.id, 'value_ids': [(4, product_attribute_value_3.id), (4, product_attribute_value_4.id)], }]) # Apply a price_extra for the attribute Aluminium cls.product_product_custo_desk.attribute_line_ids[0].product_template_value_ids[1].price_extra = 50.40 # Add a Custom attribute product_attribute_value_custom = cls.env['product.attribute.value'].create({ 'name': 'Custom', 'attribute_id': cls.product_attribute_1.id, 'sequence': 3, 'is_custom': True }) cls.product_product_custo_desk.attribute_line_ids[0].write({'value_ids': [(4, product_attribute_value_custom.id)]}) # Disable the aluminium + black product cls.product_product_custo_desk.product_variant_ids[3].active = False # Setup a first optional product img_path = get_module_resource('product', 'static', 'img', 'product_product_11-image.png') img_content = base64.b64encode(open(img_path, "rb").read()) cls.product_product_conf_chair = cls.env['product.template'].create({ 'name': 'Conference Chair (TEST)', 'image_1920': img_content, 'list_price': 16.50, }) cls.env['product.template.attribute.line'].create({ 'product_tmpl_id': cls.product_product_conf_chair.id, 'attribute_id': cls.product_attribute_1.id, 'value_ids': [(4, product_attribute_value_1.id), (4, product_attribute_value_2.id)], }) cls.product_product_conf_chair.attribute_line_ids[0].product_template_value_ids[1].price_extra = 6.40 cls.product_product_custo_desk.optional_product_ids = [(4, cls.product_product_conf_chair.id)] # Setup a second optional product cls.product_product_conf_chair_floor_protect = cls.env['product.template'].create({ 'name': 'Chair floor protection', 'list_price': 12.0, }) cls.product_product_conf_chair.optional_product_ids = [(4, cls.product_product_conf_chair_floor_protect.id)]
def _load(self, module, *args): tools.convert_file(self.cr, 'report_intrastat', get_module_resource(module, *args), {}, 'init', False, 'test', self.registry._assertion_report)
def _default_image(self): image_path = get_module_resource('hr', 'static/src/img', 'default_image.png') return tools.image_resize_image_big( base64.b64encode(open(image_path, 'rb').read()))
def _default_image(self): image_path = get_module_resource('lunch', 'static/img', 'lunch.png') return base64.b64encode(open(image_path, 'rb').read())
def _load(self, module, *args): tools.convert_file(self.cr, 'website', get_module_resource(module, *args), {}, 'init', False, 'test')
def test_02_admin_shop_custom_attribute_value_tour(self): # Make sure pricelist rule exist self.product_attribute_1 = self.env['product.attribute'].create({ 'name': 'Legs', 'sequence': 10, }) product_attribute_value_1 = self.env['product.attribute.value'].create({ 'name': 'Steel', 'attribute_id': self.product_attribute_1.id, 'sequence': 1, }) product_attribute_value_2 = self.env['product.attribute.value'].create({ 'name': 'Aluminium', 'attribute_id': self.product_attribute_1.id, 'sequence': 2, }) product_attribute_2 = self.env['product.attribute'].create({ 'name': 'Color', 'sequence': 20, }) product_attribute_value_3 = self.env['product.attribute.value'].create({ 'name': 'White', 'attribute_id': product_attribute_2.id, 'sequence': 1, }) product_attribute_value_4 = self.env['product.attribute.value'].create({ 'name': 'Black', 'attribute_id': product_attribute_2.id, 'sequence': 2, }) # Create product template self.product_product_4_product_template = self.env['product.template'].create({ 'name': 'Customizable Desk (TEST)', 'standard_price': 500.0, 'list_price': 750.0, }) # Generate variants self.env['product.template.attribute.line'].create([{ 'product_tmpl_id': self.product_product_4_product_template.id, 'attribute_id': self.product_attribute_1.id, 'value_ids': [(4, product_attribute_value_1.id), (4, product_attribute_value_2.id)], }, { 'product_tmpl_id': self.product_product_4_product_template.id, 'attribute_id': product_attribute_2.id, 'value_ids': [(4, product_attribute_value_3.id), (4, product_attribute_value_4.id)], }]) product_template = self.product_product_4_product_template # Add Custom Attribute product_attribute_value_7 = self.env['product.attribute.value'].create({ 'name': 'Custom TEST', 'attribute_id': self.product_attribute_1.id, 'sequence': 3, 'is_custom': True }) self.product_product_4_product_template.attribute_line_ids[0].write({'value_ids': [(4, product_attribute_value_7.id)]}) img_path = get_module_resource('product', 'static', 'img', 'product_product_11-image.png') img_content = base64.b64encode(open(img_path, "rb").read()) self.product_product_11_product_template = self.env['product.template'].create({ 'name': 'Conference Chair (TEST)', 'website_sequence': 9999, # laule 'image_1920': img_content, 'list_price': 16.50, }) self.env['product.template.attribute.line'].create({ 'product_tmpl_id': self.product_product_11_product_template.id, 'attribute_id': self.product_attribute_1.id, 'value_ids': [(4, product_attribute_value_1.id), (4, product_attribute_value_2.id)], }) self.product_product_11_product_template.attribute_line_ids[0].product_template_value_ids[1].price_extra = 6.40 # Setup a second optional product self.product_product_1_product_template = self.env['product.template'].create({ 'name': 'Chair floor protection', 'list_price': 12.0, }) # fix runbot, sometimes one pricelist is chosen, sometimes the other... pricelists = self.env['website'].get_current_website().get_current_pricelist() | self.env.ref('product.list0') for pricelist in pricelists: if not pricelist.item_ids.filtered(lambda i: i.product_tmpl_id == product_template and i.price_discount == 20): self.env['product.pricelist.item'].create({ 'base': 'list_price', 'applied_on': '1_product', 'pricelist_id': pricelist.id, 'product_tmpl_id': product_template.id, 'price_discount': 20, 'min_quantity': 2, 'compute_price': 'formula', }) pricelist.discount_policy = 'without_discount' self.start_tour("/", 'shop_custom_attribute_value', login="******")