コード例 #1
0
    def test_event_configurator(self):

        event = self.env['event.event'].create({
            'name':
            'Design Fair Los Angeles',
            'date_begin':
            Datetime.now() + timedelta(days=1),
            'date_end':
            Datetime.now() + timedelta(days=5),
        })

        self.env['event.event.ticket'].create([{
            'name':
            'Standard',
            'event_id':
            event.id,
            'product_id':
            self.env.ref('event_sale.product_product_event').id,
        }, {
            'name':
            'VIP',
            'event_id':
            event.id,
            'product_id':
            self.env.ref('event_sale.product_product_event').id,
        }])
        self.start_tour("/web", 'event_configurator_tour', login="******")
コード例 #2
0
ファイル: hr_employee.py プロジェクト: sheetal4123/flectra
    def _check_presence(self):
        company = self.env.company
        if not company.hr_presence_last_compute_date or \
                company.hr_presence_last_compute_date.day != Datetime.now().day:
            self.env['hr.employee'].search([
                ('company_id', '=', company.id)
            ]).write({
                'email_sent': False,
                'ip_connected': False,
                'manually_set_present': False
            })

        employees = self.env['hr.employee'].search([('company_id', '=', company.id)])
        all_employees = employees


        # Check on IP
        if literal_eval(self.env['ir.config_parameter'].sudo().get_param('hr.hr_presence_control_ip', 'False')):
            ip_list = company.hr_presence_control_ip_list
            ip_list = ip_list.split(',') if ip_list else []
            ip_employees = self.env['hr.employee']
            for employee in employees:
                employee_ips = self.env['res.users.log'].search([
                    ('create_uid', '=', employee.user_id.id),
                    ('ip', '!=', False),
                    ('create_date', '>=', Datetime.to_string(Datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)))]
                ).mapped('ip')
                if any(ip in ip_list for ip in employee_ips):
                    ip_employees |= employee
            ip_employees.write({'ip_connected': True})
            employees = employees - ip_employees

        # Check on sent emails
        if literal_eval(self.env['ir.config_parameter'].sudo().get_param('hr.hr_presence_control_email', 'False')):
            email_employees = self.env['hr.employee']
            threshold = company.hr_presence_control_email_amount
            for employee in employees:
                sent_emails = self.env['mail.message'].search_count([
                    ('author_id', '=', employee.user_id.partner_id.id),
                    ('date', '>=', Datetime.to_string(Datetime.now().replace(hour=0, minute=0, second=0, microsecond=0))),
                    ('date', '<=', Datetime.to_string(Datetime.now()))])
                if sent_emails >= threshold:
                    email_employees |= employee
            email_employees.write({'email_sent': True})
            employees = employees - email_employees

        company.sudo().hr_presence_last_compute_date = Datetime.now()

        for employee in all_employees:
            employee.hr_presence_state_display = employee.hr_presence_state
コード例 #3
0
    def test_in_date_5(self):
        """ Receive the same lot at different times, once they're in the same location, the quants
        are merged and only the earliest incoming date is kept.
        """
        lot1 = self.env['stock.production.lot'].create({
            'name':
            'lot1',
            'product_id':
            self.product_lot.id,
            'company_id':
            self.env.company.id,
        })

        from flectra.fields import Datetime
        in_date1 = Datetime.now()
        self.env['stock.quant']._update_available_quantity(self.product_lot,
                                                           self.stock_location,
                                                           1.0,
                                                           lot_id=lot1,
                                                           in_date=in_date1)

        quant = self.env['stock.quant'].search([
            ('product_id', '=', self.product_lot.id),
            ('location_id', '=', self.stock_location.id),
        ])
        self.assertEqual(len(quant), 1)
        self.assertEqual(quant.quantity, 1)
        self.assertEqual(quant.lot_id.id, lot1.id)
        self.assertEqual(quant.in_date, in_date1)

        in_date2 = Datetime.now() - timedelta(days=5)
        self.env['stock.quant']._update_available_quantity(self.product_lot,
                                                           self.stock_location,
                                                           1.0,
                                                           lot_id=lot1,
                                                           in_date=in_date2)

        quant = self.env['stock.quant'].search([
            ('product_id', '=', self.product_lot.id),
            ('location_id', '=', self.stock_location.id),
        ])
        self.assertEqual(len(quant), 1)
        self.assertEqual(quant.quantity, 2)
        self.assertEqual(quant.lot_id.id, lot1.id)
        self.assertEqual(quant.in_date, in_date2)
コード例 #4
0
ファイル: bus_controller.py プロジェクト: sheetal4123/flectra
 def poll(self, channels, last, options=None):
     if request.env.user.has_group('base.group_user'):
         ip_address = request.httprequest.remote_addr
         users_log = request.env['res.users.log'].search_count([
             ('create_uid', '=', request.env.user.id),
             ('ip', '=', ip_address),
             ('create_date', '>=', Datetime.to_string(Datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)))])
         if not users_log:
             with registry(request.env.cr.dbname).cursor() as cr:
                 env = Environment(cr, request.env.user.id, {})
                 env['res.users.log'].create({'ip': ip_address})
     return super(BusController, self).poll(channels, last, options=options)
コード例 #5
0
ファイル: hr_employee.py プロジェクト: sheetal4123/flectra
 def _compute_presence_state(self):
     super()._compute_presence_state()
     employees = self.filtered(lambda e: e.hr_presence_state != 'present' and not e.is_absent)
     company = self.env.company
     employee_to_check_working = employees.filtered(lambda e:
                                                    not e.is_absent and
                                                    (e.email_sent or e.ip_connected or e.manually_set_present))
     working_now_list = employee_to_check_working._get_employee_working_now()
     for employee in employees:
         if not employee.is_absent and company.hr_presence_last_compute_date and employee.id in working_now_list and \
                 company.hr_presence_last_compute_date.day == Datetime.now().day and \
                 (employee.email_sent or employee.ip_connected or employee.manually_set_present):
             employee.hr_presence_state = 'present'
コード例 #6
0
    def _get_car_atn(self, acquisition_date, car_value, fuel_type, co2):
        # Compute the correction coefficient from the age of the car
        now = Datetime.from_string(Datetime.now())
        start = Datetime.from_string(acquisition_date)
        if start:
            number_of_month = (
                now.year - start.year) * 12.0 + now.month - start.month + int(
                    bool(now.day - start.day + 1))
            if number_of_month <= 12:
                age_coefficient = 1.00
            elif number_of_month <= 24:
                age_coefficient = 0.94
            elif number_of_month <= 36:
                age_coefficient = 0.88
            elif number_of_month <= 48:
                age_coefficient = 0.82
            elif number_of_month <= 60:
                age_coefficient = 0.76
            else:
                age_coefficient = 0.70
            car_value = car_value * age_coefficient
            # Compute atn value from corrected car_value
            magic_coeff = 6.0 / 7.0  # Don't ask me why
            if fuel_type == 'electric':
                atn = 0.0
            else:
                if fuel_type in ['diesel', 'hybrid']:
                    reference = 88.0
                else:
                    reference = 107.0

                if not co2:
                    co2 = 195 if fuel_type in ['diesel', 'hybrid'] else 205

                if co2 <= reference:
                    atn = car_value * max(0.04,
                                          (0.055 - 0.001 *
                                           (reference - co2))) * magic_coeff
                else:
                    atn = car_value * min(0.18,
                                          (0.055 + 0.001 *
                                           (co2 - reference))) * magic_coeff
            return max(1310, atn) / 12.0
コード例 #7
0
    def setUp(self):
        super(TestPurchaseReceptionNotify, self).setUp()
        self.purchase_order_model = self.env['purchase.order']
        purchase_order_line_model = self.env['purchase.order.line']
        partner_model = self.env['res.partner']
        prod_model = self.env['product.product']
        self.product_uom_model = self.env['product.uom']

        # partners
        pa_dict = {
            'name': 'Partner 1',
            'supplier': True,
        }
        self.partner = partner_model.sudo().create(pa_dict)

        # Purchase Order Num 1
        po_dict = {
            'partner_id': self.partner.id,
        }
        self.purchase_order = self.purchase_order_model.create(po_dict)
        uom_id = self.product_uom_model.search([('name', '=', 'Unit(s)')
                                                ])[0].id
        pr_dict = {
            'name': 'Product Test',
            'uom_id': uom_id,
            'purchase_method': 'purchase',
        }
        self.product = prod_model.sudo().create(pr_dict)
        pl_dict1 = {
            'date_planned': Datetime.now(),
            'name': 'PO01',
            'order_id': self.purchase_order.id,
            'product_id': self.product.id,
            'product_uom': uom_id,
            'price_unit': 1.0,
            'product_qty': 5.0,
        }
        self.purchase_order_line = \
            purchase_order_line_model.sudo().create(pl_dict1)
        self.purchase_order.button_confirm()
コード例 #8
0
    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,
                         })]
                     })
                 ]
             })]
        })
コード例 #9
0
ファイル: fleet.py プロジェクト: vincentchen/flectra
 def _compute_atn(self):
     now = Datetime.now()
     for model in self:
         model.default_atn = self.env['fleet.vehicle']._get_car_atn(
             now, model.default_car_value, model.default_fuel_type,
             model.default_co2)
コード例 #10
0
    def setUp(self):
        super(TestPurchaseOpenQty, self).setUp()
        self.purchase_order_model = self.env['purchase.order']
        purchase_order_line_model = self.env['purchase.order.line']
        partner_model = self.env['res.partner']
        prod_model = self.env['product.product']
        analytic_account_model = self.env['account.analytic.account']
        self.product_uom_model = self.env['product.uom']

        # partners
        pa_dict = {
            'name': 'Partner 1',
            'supplier': True,
        }
        self.partner = partner_model.sudo().create(pa_dict)
        pa_dict2 = {
            'name': 'Partner 2',
            'supplier': True,
        }
        self.partner2 = partner_model.sudo().create(pa_dict2)

        # account
        ac_dict = {
            'name': 'analytic account 1',
        }
        self.analytic_account_1 = \
            analytic_account_model.sudo().create(ac_dict)

        # Purchase Order Num 1
        po_dict = {
            'partner_id': self.partner.id,
        }
        self.purchase_order_1 = self.purchase_order_model.create(po_dict)
        uom_id = self.product_uom_model.search([('name', '=', 'Unit(s)')
                                                ])[0].id
        pr_dict = {
            'name': 'Product Test',
            'uom_id': uom_id,
            'purchase_method': 'purchase',
        }
        self.product = prod_model.sudo().create(pr_dict)
        pl_dict1 = {
            'date_planned': Datetime.now(),
            'name': 'PO01',
            'order_id': self.purchase_order_1.id,
            'product_id': self.product.id,
            'product_uom': uom_id,
            'price_unit': 1.0,
            'product_qty': 5.0,
            'account_analytic_id': self.analytic_account_1.id,
        }
        self.purchase_order_line_1 = \
            purchase_order_line_model.sudo().create(pl_dict1)
        self.purchase_order_1.button_confirm()

        # Purchase Order Num 2
        po_dict2 = {
            'partner_id': self.partner2.id,
        }
        self.purchase_order_2 = self.purchase_order_model.create(po_dict2)
        pr_dict2 = {
            'name': 'Product Test 2',
            'uom_id': uom_id,
            'purchase_method': 'receive',
        }
        self.product2 = prod_model.sudo().create(pr_dict2)
        pl_dict2 = {
            'date_planned': Datetime.now(),
            'name': 'PO02',
            'order_id': self.purchase_order_2.id,
            'product_id': self.product2.id,
            'product_uom': uom_id,
            'price_unit': 1.0,
            'product_qty': 5.0,
            'account_analytic_id': self.analytic_account_1.id,
        }
        self.purchase_order_line_2 = \
            purchase_order_line_model.sudo().create(pl_dict2)
        self.purchase_order_2.button_confirm()
コード例 #11
0
    def test_course_certification_employee(self):
        user_demo = self.user_demo
        user_demo.flush()
        # Avoid Billing/Shipping address page
        user_demo.write({
            'groups_id': [(5, 0), (4, self.env.ref('base.group_user').id)],
            'street':
            '215 Vine St',
            'city':
            'Scranton',
            'zip':
            '18503',
            'country_id':
            self.env.ref('base.us').id,
            'state_id':
            self.env.ref('base.state_us_39').id,
            'phone':
            '+1 555-555-5555',
            'email':
            '*****@*****.**',
        })

        # Specify Accounting Data
        cash_journal = self.env['account.journal'].create({
            'name': 'Cash - Test',
            'type': 'cash',
            'code': 'CASH - Test'
        })
        self.env['payment.acquirer'].search([('journal_id', '=', False)
                                             ]).journal_id = cash_journal
        a_recv = self.env['account.account'].create({
            'code':
            'X1012',
            'name':
            'Debtors - (test)',
            'reconcile':
            True,
            'user_type_id':
            self.env.ref('account.data_account_type_receivable').id,
        })
        a_pay = self.env['account.account'].create({
            'code':
            'X1111',
            'name':
            'Creditors - (test)',
            'user_type_id':
            self.env.ref('account.data_account_type_payable').id,
            'reconcile':
            True,
        })

        Property = self.env['ir.property']
        Property._set_default('property_account_receivable_id', 'res.partner',
                              a_recv, self.env.company)
        Property._set_default('property_account_payable_id', 'res.partner',
                              a_pay, self.env.company)

        product_course_channel_6 = self.env['product.product'].create({
            'name':
            'DIY Furniture Course',
            'list_price':
            100.0,
            'type':
            'service',
            'is_published':
            True,
        })

        furniture_survey = self.env['survey.survey'].create({
            'title':
            'Furniture Creation Certification',
            'access_token':
            '5632a4d7-48cf-aaaa-8c52-2174d58cf50b',
            'state':
            'open',
            'access_mode':
            'public',
            'users_can_go_back':
            True,
            'users_login_required':
            True,
            'scoring_type':
            'scoring_with_answers',
            'certification':
            True,
            'certification_mail_template_id':
            self.env.ref('survey.mail_template_certification').id,
            'is_attempts_limited':
            True,
            'attempts_limit':
            3,
            'description':
            "<p>Test your furniture knowledge!</p>",
            'question_and_page_ids':
            [(0, 0, {
                'title':
                'Furniture',
                'sequence':
                1,
                'is_page':
                True,
                'description':
                "&lt;p&gt;Test your furniture knowledge!&lt;/p&gt",
            }),
             (0, 0, {
                 'title':
                 'What type of wood is the best for furniture?',
                 'sequence':
                 2,
                 'question_type':
                 'simple_choice',
                 'constr_mandatory':
                 True,
                 'suggested_answer_ids': [(0, 0, {
                     'value': 'Fir',
                     'sequence': 1,
                 }),
                                          (0, 0, {
                                              'value': 'Oak',
                                              'sequence': 2,
                                              'is_correct': True,
                                              'answer_score': 2.0,
                                          }),
                                          (0, 0, {
                                              'value': 'Ash',
                                              'sequence': 3,
                                          }),
                                          (0, 0, {
                                              'value': 'Beech',
                                              'sequence': 4,
                                          })]
             }),
             (0, 0, {
                 'title':
                 'Select all the furniture shown in the video',
                 'sequence':
                 3,
                 'question_type':
                 'multiple_choice',
                 'column_nb':
                 '4',
                 'suggested_answer_ids': [(0, 0, {
                     'value': 'Chair',
                     'sequence': 1,
                     'is_correct': True,
                     'answer_score': 1.0,
                 }),
                                          (0, 0, {
                                              'value': 'Table',
                                              'sequence': 2,
                                              'answer_score': -1.0,
                                          }),
                                          (0, 0, {
                                              'value': 'Desk',
                                              'sequence': 3,
                                              'is_correct': True,
                                              'answer_score': 1.0,
                                          }),
                                          (0, 0, {
                                              'value': 'Shelve',
                                              'sequence': 4,
                                              'is_correct': True,
                                              'answer_score': 1.0,
                                          }),
                                          (0, 0, {
                                              'value': 'Bed',
                                              'sequence': 5,
                                              'answer_score': -1.0,
                                          })]
             }),
             (0, 0, {
                 'title':
                 'What do you think about the content of the course? (not rated)',
                 'sequence': 4,
                 'question_type': 'text_box',
             })]
        })

        slide_channel_demo_6_furn3 = self.env['slide.channel'].create({
            'name':
            'DIY Furniture - TEST',
            'user_id':
            self.env.ref('base.user_admin').id,
            'enroll':
            'payment',
            'product_id':
            product_course_channel_6.id,
            'channel_type':
            'training',
            'allow_comment':
            True,
            'promote_strategy':
            'most_voted',
            'is_published':
            True,
            'description':
            'So much amazing certification.',
            'create_date':
            Datetime.now() - relativedelta(days=2),
            'slide_ids': [(0, 0, {
                'name': 'DIY Furniture Certification',
                'sequence': 1,
                'slide_type': 'certification',
                'category_id': False,
                'is_published': True,
                'is_preview': False,
                'description': "It's time to test your knowledge!",
                'survey_id': furniture_survey.id,
            })]
        })

        self.browser_js(
            '/slides',
            'flectra.__DEBUG__.services["web_tour.tour"].run("certification_member")',
            'flectra.__DEBUG__.services["web_tour.tour"].tours.certification_member.ready',
            login=user_demo.login)