当前位置: 首页>>代码示例>>Python>>正文


Python fields.Date类代码示例

本文整理汇总了Python中odoo.fields.Date的典型用法代码示例。如果您正苦于以下问题:Python Date类的具体用法?Python Date怎么用?Python Date使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Date类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_calendar_work_days_intervals_timezone

    def test_calendar_work_days_intervals_timezone(self):
        # _get_day_work_intervals converts from the timezone
        # of the user into UTC
        self.env.user.tz = 'US/Alaska'
        (self.leave1 | self.leave2 | self.leave3).unlink()
        leave = self.env['resource.calendar.leaves'].create({
            'name': 'Timezoned Leaves',
            'calendar_id': self.calendar.id,
            'resource_id': self.resource1_id,
            'date_from': to_naive_utc(Datetime.from_string('2013-02-21 10:00:00'), self.env.user),
            'date_to': to_naive_utc(Datetime.from_string('2013-02-26 12:00:00'), self.env.user)
        })

        def to_tuple(interval):
            return (interval.start_datetime, interval.end_datetime)

        intervals = self.calendar._get_day_work_intervals(Date.from_string('2013-02-26'), time(10), time(18), False, self.resource1_id)
        self.assertEqual(to_tuple(intervals[0]), (Datetime.from_string('2013-02-26 19:00:00'), Datetime.from_string('2013-02-27 01:00:00')))
        intervals = self.calendar._get_day_work_intervals(Date.from_string('2013-02-26'), time(10), time(18), True, self.resource1_id)
        self.assertEqual(to_tuple(intervals[0]), (Datetime.from_string('2013-02-26 21:00:00'), Datetime.from_string('2013-02-27 01:00:00')))

        self.env.user.tz = 'Japan'

        intervals = self.calendar._get_day_work_intervals(Date.from_string('2013-02-26'), time(10), time(18), False, self.resource1_id)
        self.assertEqual(to_tuple(intervals[0]), (Datetime.from_string('2013-02-26 01:00:00'), Datetime.from_string('2013-02-26 07:00:00')))
        intervals = self.calendar._get_day_work_intervals(Date.from_string('2013-02-26'), time(10), time(18), True, self.resource1_id)
        self.assertEqual(to_tuple(intervals[0]), (Datetime.from_string('2013-02-26 03:00:00'), Datetime.from_string('2013-02-26 07:00:00')))
开发者ID:JosDeGraeve,项目名称:odoo,代码行数:27,代码来源:test_resource.py

示例2: test_payslip_generation_with_extra_work

    def test_payslip_generation_with_extra_work(self):
        # /!\ this is in the weekend (Sunday) => no calendar attendance at this time
        start = self.to_datetime_tz('2015-11-01 10:00:00', tz=pytz.utc)
        end = self.to_datetime_tz('2015-11-01 17:00:00', tz=pytz.utc)
        benef = self.env['hr.benefit'].create({
            'name': 'Extra',
            'employee_id': self.richard_emp.id,
            'contract_id': self.richard_emp.contract_id.id,
            'benefit_type_id': self.benefit_type.id,
            'date_start': start,
            'date_stop': end,
        })
        benef.action_validate(benef.ids)
        payslip_wizard = self.env['hr.payslip.employees'].create({'employee_ids': [(4, self.richard_emp.id)]})
        payslip_wizard.with_context({
            'default_date_start': Date.to_string(start),
            'default_date_end': Date.to_string(end + relativedelta(days=1))
            }).compute_sheet()
        payslip = self.env['hr.payslip'].search([('employee_id', '=', self.richard_emp.id)])
        work_line = payslip.worked_days_line_ids.filtered(lambda l: l.code == 'WORK100') # From default calendar.attendance
        leave_line = payslip.worked_days_line_ids.filtered(lambda l: l.code == 'WORK200')

        self.assertTrue(work_line, "It should have a work line in the payslip")
        self.assertTrue(leave_line, "It should have an extra work line in the payslip")
        self.assertEqual(work_line.number_of_hours, 8.0, "It should have 8 hours of work") # Monday
        self.assertEqual(leave_line.number_of_hours, 7.0, "It should have 5 hours of extra work") # Sunday
开发者ID:JeffBNimble,项目名称:odoo,代码行数:26,代码来源:test_benefit.py

示例3: test_leave

    def test_leave(self):
        def to_tuple(interval):
            return (interval.start_datetime, interval.end_datetime)

        # Here we test if the leaves are correctly computed in the case our user is in UTC
        # NB: Beware of winter/spring time
        work_no_tz = [to_tuple(x) for x in self.calendar._get_day_leave_intervals(Date.from_string('2018-12-25'), time(0), time(23, 59, 59), self.resource1_id)]
        self.assertEqual(work_no_tz[0], (Datetime.from_string('2018-12-25 08:00:00'), Datetime.from_string('2018-12-25 16:00:00')))

        work_user_tz = [to_tuple(x) for x in self.calendar._get_day_leave_intervals(Date.from_string('2018-05-01'), time(0), time(23, 59, 59), self.resource1_id)]
        self.assertEqual(work_user_tz[0], (Datetime.from_string('2018-05-01 08:00:00'), Datetime.from_string('2018-05-01 16:00:00')))

        work_spec = [to_tuple(x) for x in self.calendar._get_day_leave_intervals(Date.from_string('2018-04-06'), time(0), time(23, 59, 59), self.resource1_id)]
        self.assertEqual(work_spec[0], (Datetime.from_string('2018-04-06 08:00:00'), Datetime.from_string('2018-04-06 13:00:00')))
开发者ID:JZ10UJS,项目名称:odoo,代码行数:14,代码来源:test_resource.py

示例4: test_calendar_previous_day

    def test_calendar_previous_day(self):
        # Test: previous day: previous day before day1 is (day4-7)
        date = self.calendar._get_previous_work_day(day_date=Date.from_string('2013-02-12'))
        self.assertEqual(date, self.date2.date() + relativedelta(days=-7))

        # Test: previous day: previous day before day4 is day1
        date = self.calendar._get_previous_work_day(day_date=Date.from_string('2013-02-15'))
        self.assertEqual(date, self.date1.date())

        # Test: previous day: previous day before day4+1 is day4
        date = self.calendar._get_previous_work_day(day_date=Date.from_string('2013-02-15') + relativedelta(days=1))
        self.assertEqual(date, self.date2.date())

        # Test: previous day: previous day before day1-1 is (day4-7)
        date = self.calendar._get_previous_work_day(day_date=Date.from_string('2013-02-12') + relativedelta(days=-1))
        self.assertEqual(date, self.date2.date() + relativedelta(days=-7))
开发者ID:1806933,项目名称:odoo,代码行数:16,代码来源:test_resource.py

示例5: test_leaves_timezones

    def test_leaves_timezones(self):
        self.env.user.tz = 'US/Alaska' # UTC-9

        def to_tuple(interval):
            return (interval.start_datetime, interval.end_datetime)

        # Here we test if the leaves are correctly computed in the case our user is in tz Alaska
        # NB: Beware of winter/spring time
        work_no_tz = [to_tuple(x) for x in self.calendar._get_day_leave_intervals(Date.from_string('2018-12-25'), time(0), time(23, 59, 59), self.resource1_id)]
        self.assertEqual(work_no_tz[0], (Datetime.from_string('2018-12-25 17:00:00'), Datetime.from_string('2018-12-26 01:00:00')))

        work_user_tz = [to_tuple(x) for x in self.calendar._get_day_leave_intervals(Date.from_string('2018-05-01'), time(0), time(23, 59, 59), self.resource1_id)]
        self.assertEqual(work_user_tz[0], (Datetime.from_string('2018-05-01 16:00:00'), Datetime.from_string('2018-05-02 00:00:00')))

        work_spec = [to_tuple(x) for x in self.calendar._get_day_leave_intervals(Date.from_string('2018-04-06'), time(0), time(23, 59, 59), self.resource1_id)]
        self.assertEqual(work_spec[0], (Datetime.from_string('2018-04-06 16:00:00'), Datetime.from_string('2018-04-06 21:00:00')))
开发者ID:JZ10UJS,项目名称:odoo,代码行数:16,代码来源:test_resource.py

示例6: test_calendar_next_day

    def test_calendar_next_day(self):
        # Test: next day: next day after day1 is day4
        date = self.calendar._get_next_work_day(day_date=Date.from_string('2013-02-12'))
        self.assertEqual(date, self.date2.date())

        # Test: next day: next day after day4 is (day1+7)
        date = self.calendar._get_next_work_day(day_date=Date.from_string('2013-02-15'))
        self.assertEqual(date, self.date1.date() + relativedelta(days=7))

        # Test: next day: next day after day4+1 is (day1+7)
        date = self.calendar._get_next_work_day(day_date=Date.from_string('2013-02-15') + relativedelta(days=1))
        self.assertEqual(date, self.date1.date() + relativedelta(days=7))

        # Test: next day: next day after day1-1 is day1
        date = self.calendar._get_next_work_day(day_date=Date.from_string('2013-02-12') + relativedelta(days=-1))
        self.assertEqual(date, self.date1.date())
开发者ID:1806933,项目名称:odoo,代码行数:16,代码来源:test_resource.py

示例7: _get_car_atn

    def _get_car_atn(self, acquisition_date, car_value, fuel_type, co2):
        # Compute the correction coefficient from the age of the car
        now = Date.today()
        if acquisition_date:
            number_of_month = ((now.year - acquisition_date.year) * 12.0 + now.month -
                               acquisition_date.month +
                               int(bool(now.day - acquisition_date.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 = 87.0
                else:
                    reference = 105.0

                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(1280, atn) / 12.0
开发者ID:Gorrice,项目名称:odoo,代码行数:35,代码来源:fleet.py

示例8: test_calendar_working_day_intervals_leaves_generic

    def test_calendar_working_day_intervals_leaves_generic(self):
        # Test: day0 with leaves outside range: 1 interval
        intervals = self.calendar._get_day_work_intervals(Date.from_string('2013-02-12'), start_time=time(7, 0, 0), compute_leaves=True)
        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0][:2], (Datetime.from_string('2013-02-12 08:00:00'), Datetime.from_string('2013-02-12 16:00:00')))

        # Test: day0 with leaves: 2 intervals because of leave between 9 and 12, ending at 15:45:30
        intervals = self.calendar._get_day_work_intervals(Date.from_string('2013-02-19'),
                                                          start_time=time(8, 15, 0),
                                                          end_time=time(15, 45, 30),
                                                          compute_leaves=True)
        self.assertEqual(len(intervals), 2)
        self.assertEqual(intervals[0][:2], (Datetime.from_string('2013-02-19 08:15:00'), Datetime.from_string('2013-02-19 09:00:00')))
        self.assertEqual(intervals[1][:2], (Datetime.from_string('2013-02-19 12:00:00'), Datetime.from_string('2013-02-19 15:45:30')))
        self.assertEqual(intervals[0][2]['attendances'], self.att_1)
        self.assertEqual(intervals[0][2]['leaves'], self.leave1)
        self.assertEqual(intervals[1][2]['attendances'], self.att_1)
        self.assertEqual(intervals[0][2]['leaves'], self.leave1)
开发者ID:1806933,项目名称:odoo,代码行数:18,代码来源:test_resource.py

示例9: _get_archive_groups

 def _get_archive_groups(self, model, domain=None, fields=None, groupby="create_date", order="create_date desc"):
     if not model:
         return []
     if domain is None:
         domain = []
     if fields is None:
         fields = ['name', 'create_date']
     groups = []
     for group in request.env[model]._read_group_raw(domain, fields=fields, groupby=groupby, orderby=order):
         dates, label = group[groupby]
         date_begin, date_end = dates.split('/')
         groups.append({
             'date_begin': Date.to_string(Date.from_string(date_begin)),
             'date_end': Date.to_string(Date.from_string(date_end)),
             'name': label,
             'item_count': group[groupby + '_count']
         })
     return groups
开发者ID:anybox,项目名称:odoo,代码行数:18,代码来源:main.py

示例10: test_calendar_working_day_intervals_leaves_resource

 def test_calendar_working_day_intervals_leaves_resource(self):
     # Test: day1+14 on leave, with resource leave computation
     intervals = self.calendar._get_day_work_intervals(
         Date.from_string('2013-02-26'),
         start_time=time(7, 0, 0),
         compute_leaves=True,
         resource_id=self.resource1_id
     )
     # Result: nothing, because on leave
     self.assertEqual(len(intervals), 0)
开发者ID:1806933,项目名称:odoo,代码行数:10,代码来源:test_resource.py

示例11: _get_archive_groups

 def _get_archive_groups(self, model, domain=None, fields=None, groupby="create_date", order="create_date desc"):
     if not model:
         return []
     if domain is None:
         domain = []
     if fields is None:
         fields = ["name", "create_date"]
     groups = []
     for group in request.env[model]._read_group_raw(domain, fields=fields, groupby=groupby, orderby=order):
         dates, label = group[groupby]
         date_begin, date_end = dates.split("/")
         groups.append(
             {
                 "date_begin": Date.to_string(Date.from_string(date_begin)),
                 "date_end": Date.to_string(Date.from_string(date_end)),
                 "name": label,
                 "item_count": group[groupby + "_count"],
             }
         )
     return groups
开发者ID:sunjie20081001,项目名称:odoo,代码行数:20,代码来源:main.py

示例12: test_calendar_working_day_intervals_no_leaves

    def test_calendar_working_day_intervals_no_leaves(self):
        # Test: day0 without leaves: 1 interval
        intervals = self.calendar._get_day_work_intervals(Date.from_string('2013-02-12'), start_time=time(9, 8, 7))
        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0][:2], (Datetime.from_string('2013-02-12 09:08:07'), Datetime.from_string('2013-02-12 16:00:00')))
        self.assertEqual(intervals[0][2]['attendances'], self.att_1)

        # Test: day1, beginning at 10:30 -> work from 10:30 (arrival) until 16:00
        intervals = self.calendar._get_day_work_intervals(Date.from_string('2013-02-19'), start_time=time(10, 30, 0))
        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0][:2], (Datetime.from_string('2013-02-19 10:30:00'), Datetime.from_string('2013-02-19 16:00:00')))
        self.assertEqual(intervals[0][2]['attendances'], self.att_1)

        # Test: day3 without leaves: 2 interval
        intervals = self.calendar._get_day_work_intervals(Date.from_string('2013-02-15'), start_time=time(10, 11, 12))
        self.assertEqual(len(intervals), 2)
        self.assertEqual(intervals[0][:2], (Datetime.from_string('2013-02-15 10:11:12'), Datetime.from_string('2013-02-15 13:00:00')))
        self.assertEqual(intervals[1][:2], (Datetime.from_string('2013-02-15 16:00:00'), Datetime.from_string('2013-02-15 23:00:00')))
        self.assertEqual(intervals[0][2]['attendances'], self.att_2)
        self.assertEqual(intervals[1][2]['attendances'], self.att_3)
开发者ID:1806933,项目名称:odoo,代码行数:20,代码来源:test_resource.py

示例13: setUp

    def setUp(self):
        super(TestPayslipBase, self).setUp()

        # Some salary rules references
        self.hra_rule_id = self.ref('hr_payroll.hr_salary_rule_houserentallowance1')
        self.conv_rule_id = self.ref('hr_payroll.hr_salary_rule_convanceallowance1')
        self.prof_tax_rule_id = self.ref('hr_payroll.hr_salary_rule_professionaltax1')
        self.pf_rule_id = self.ref('hr_payroll.hr_salary_rule_providentfund1')
        self.mv_rule_id = self.ref('hr_payroll.hr_salary_rule_meal_voucher')
        self.comm_rule_id = self.ref('hr_payroll.hr_salary_rule_sales_commission')

        # I create a new employee "Richard"
        self.richard_emp = self.env['hr.employee'].create({
            'name': 'Richard',
            'gender': 'male',
            'birthday': '1984-05-01',
            'country_id': self.ref('base.be'),
            'department_id': self.ref('hr.dep_rd')
        })

        # I create a salary structure for "Software Developer"
        self.developer_pay_structure = self.env['hr.payroll.structure'].create({
            'name': 'Salary Structure for Software Developer',
            'code': 'SD',
            'company_id': self.ref('base.main_company'),
            'rule_ids': [(4, self.hra_rule_id), (4, self.conv_rule_id),
                         (4, self.prof_tax_rule_id), (4, self.pf_rule_id),
                         (4, self.mv_rule_id), (4, self.comm_rule_id)],
        })

        # I create a contract for "Richard"
        self.env['hr.contract'].create({
            'date_end': Date.to_string((datetime.now() + timedelta(days=365))),
            'date_start': Date.today(),
            'name': 'Contract for Richard',
            'wage': 5000.0,
            'type_id': self.ref('hr_contract.hr_contract_type_emp'),
            'employee_id': self.richard_emp.id,
            'struct_id': self.developer_pay_structure.id,
        })
开发者ID:10537,项目名称:odoo,代码行数:40,代码来源:common.py

示例14: test_account_budget

    def test_account_budget(self):

        # Creating a crossovered.budget record
        budget = self.env["crossovered.budget"].create(
            {
                "date_from": Date.from_string("%s-01-01" % (datetime.datetime.now().year + 1)),
                "date_to": Date.from_string("%s-12-31" % (datetime.datetime.now().year + 1)),
                "name": "Budget %s" % (datetime.datetime.now().year + 1),
                "state": "draft",
            }
        )

        # I created two different budget lines
        # Modifying a crossovered.budget record
        self.env["crossovered.budget.lines"].create(
            {
                "crossovered_budget_id": budget.id,
                "analytic_account_id": self.ref("analytic.analytic_partners_camp_to_camp"),
                "date_from": Date.from_string("%s-01-01" % (datetime.datetime.now().year + 1)),
                "date_to": Date.from_string("%s-12-31" % (datetime.datetime.now().year + 1)),
                "general_budget_id": self.account_budget_post_purchase0.id,
                "planned_amount": 10000.0,
            }
        )
        self.env["crossovered.budget.lines"].create(
            {
                "crossovered_budget_id": budget.id,
                "analytic_account_id": self.ref("analytic.analytic_our_super_product"),
                "date_from": Date.from_string("%s-09-01" % (datetime.datetime.now().year + 1)),
                "date_to": Date.from_string("%s-09-30" % (datetime.datetime.now().year + 1)),
                "general_budget_id": self.account_budget_post_sales0.id,
                "planned_amount": 400000.0,
            }
        )
        # I check that Initially Budget is in "draft" state
        self.assertEqual(budget.state, "draft")

        # I pressed the confirm button to confirm the Budget
        # Performing an action confirm on module crossovered.budget
        budget.action_budget_confirm()

        # I check that budget is in "Confirmed" state
        self.assertEqual(budget.state, "confirm")

        # I pressed the validate button to validate the Budget
        # Performing an action validate on module crossovered.budget
        budget.action_budget_validate()

        # I check that budget is in "Validated" state
        self.assertEqual(budget.state, "validate")

        # I pressed the done button to set the Budget to "Done" state
        # Performing an action done on module crossovered.budget
        budget.action_budget_done()

        # I check that budget is in "done" state
        self.assertEqual(budget.state, "done")
开发者ID:RibraX,项目名称:odoo,代码行数:57,代码来源:test_account_budget.py

示例15: test_theoritical_amount_with_paid_date

 def test_theoritical_amount_with_paid_date(self):
     test_list = [
         (str(datetime.now().year) + '-01-01', 0),
         (str(datetime.now().year) + '-01-02', 0),
         (str(datetime.now().year) + '-09-08', 0),
         (str(datetime.now().year) + '-09-09', 0),
         (str(datetime.now().year) + '-09-10', -364),
         (str(self.last_day_of_budget.date()), -364),
     ]
     for date, expected_amount in test_list:
         _logger.info("Checking theoritical amount for the date: " + date)
         self.mock_date.today.return_value = Date.from_string(date)
         self.assertAlmostEqual(self.paid_date_line.theoritical_amount, expected_amount)
         #invalidate the cache of the budget lines to recompute the theoritical amount at next iteration
         self.paid_date_line.invalidate_cache()
开发者ID:astirpe,项目名称:odoo,代码行数:15,代码来源:test_theoreticalamount.py


注:本文中的odoo.fields.Date类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。