本文整理汇总了Python中odoo.fields.Date.to_string方法的典型用法代码示例。如果您正苦于以下问题:Python Date.to_string方法的具体用法?Python Date.to_string怎么用?Python Date.to_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类odoo.fields.Date
的用法示例。
在下文中一共展示了Date.to_string方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_payslip_generation_with_extra_work
# 需要导入模块: from odoo.fields import Date [as 别名]
# 或者: from odoo.fields.Date import to_string [as 别名]
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
示例2: _get_archive_groups
# 需要导入模块: from odoo.fields import Date [as 别名]
# 或者: from odoo.fields.Date import to_string [as 别名]
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
示例3: _get_archive_groups
# 需要导入模块: from odoo.fields import Date [as 别名]
# 或者: from odoo.fields.Date import to_string [as 别名]
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
示例4: setUp
# 需要导入模块: from odoo.fields import Date [as 别名]
# 或者: from odoo.fields.Date import to_string [as 别名]
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,
})
示例5: test_payslip_generation_with_leave
# 需要导入模块: from odoo.fields import Date [as 别名]
# 或者: from odoo.fields.Date import to_string [as 别名]
def test_payslip_generation_with_leave(self):
# /!\ this is a week day => it exists an calendar attendance at this time
start = self.to_datetime_tz('2015-11-02 10:00:00', tz=pytz.utc)
end = self.to_datetime_tz('2015-11-02 17:00:00', tz=pytz.utc)
leave_benef = self.env['hr.benefit'].create({
'name': '1leave',
'employee_id': self.richard_emp.id,
'contract_id': self.richard_emp.contract_id.id,
'benefit_type_id': self.benefit_type_leave.id,
'date_start': start,
'date_stop': end,
})
leave_benef.action_validate(leave_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)}).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 == 'LEAVE100')
self.assertTrue(work_line, "It should have a work line in the payslip")
self.assertTrue(leave_line, "It should have a leave line in the payslip")
self.assertEqual(work_line.number_of_hours, 3.0, "It should have 3 hours of work")
self.assertEqual(leave_line.number_of_hours, 5.0, "It should have 5 hours of leave")
示例6: dump_date
# 需要导入模块: from odoo.fields import Date [as 别名]
# 或者: from odoo.fields.Date import to_string [as 别名]
def dump_date(self, value, write):
value = Date.to_string(value)
self.dump_unicode(value, write)