3
我已經創建了一個表格,我想要通過填寫所有信息,但條件是應該沒有任何重複條目在所有領域相同的條目,ATLEAST一個不同條目將工作..我想保存一個至少有一個字段的odoo表格應該是不同的,並且不會重複保存表格
這裏是我的代碼 -
class HRLeaveRules(models.Model):
_name = 'hr_leave_rules.leave_rules'
half_day_allowed = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Half Day Allowed", required=True)
gender_specific = fields.Selection([
('all' ,"All"),
('male',"Male"),
('female',"Female")],
string="Gender Specific", required=True)
leaves_allowed_on_prorata_basis = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Leaves allowed on pro rata basis", required=True)
leave_encashment = fields.Boolean(string="Leave Encashment",
required=True)
leave_encashment_for_maximum = fields.Integer(
string = "Leave Encashment for maximum", required=True)
can_emp_club_leave = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Can Employees Club this leave with any other leave",
required=True)
past_dated_leave_allowed = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Past dated leave application allowed", required=True)
override_paid_leave_to_unpaid = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Can managers override paid leaves to unpaid", required=True)
carry_frwrdng_leaves = fields.Boolean(string="Carry forwarding of leaves",
required=True)
maximum_accumulation_in_year = fields.Integer(string = "Maximum Accumulation in year",
required=True)
leave_encash_rest_leaves = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Leave Encashment for Rest Leaves", required=True)
employee_id = fields.Many2one('hr.employee', string="Employee")
holiday_status_id = fields.Many2one("hr.holidays.status",
string="Leave Type", required=True)
department_id = fields.Many2one('hr.department',
related='employee_id.department_id', string='Department')
count_intervening_leaves = fields.Boolean(
string="Count intervening holidays/weekly offs as leaves",
required=True)
count_intervening_leaves_back_date = fields.Boolean(
string="Count intervening holidays/weekly offs as leaves if applying for back date",
required=True)
leaves_probation_period = fields.Boolean(string="Leaves allowed in probation period",
required=True)
max_con_leaves_month = fields.Boolean(string="Maximum consecutive leaves per month",
required=True)
leave_encashment_cycle = fields.Selection([
('annually',"Annually"),
('super_annuation',"Super Annuation/Relieving")],
string="Leave Encashment Cycle", required=True)
description = fields.Text(string="Description")
@api.model
def create(self,value):
current = self.env['hr_leave_rules.leave_rules'].search([])
for rec in current:
if value.has_key("holiday_status_id"):
if rec.holiday_status_id.id == value["holiday_status_id"] and rec.holiday_status_id:
if value.has_key("gender_specific"):
if rec.gender_specific == value["gender_specific"] and rec.gender_specific:
if value.has_key("half_day_allowed"):
if rec.half_day_allowed == value["half_day_allowed"] and rec.half_day_allowed:
if value.has_key("leaves_allowed_on_prorata_basis"):
if rec.leaves_allowed_on_prorata_basis == value["leaves_allowed_on_prorata_basis"] and rec.leaves_allowed_on_prorata_basis:
if value.has_key("leave_encashment_cycle"):
if rec.leave_encashment_cycle == value["leave_encashment_cycle"] and rec.leave_encashment_cycle:
if value.has_key("leave_encash_rest_leaves"):
if rec.leave_encash_rest_leaves == value["leave_encash_rest_leaves"] and rec.leave_encash_rest_leaves:
if value.has_key("can_emp_club_leave"):
if rec.can_emp_club_leave == value["can_emp_club_leave"] and rec.can_emp_club_leave:
if value.has_key("past_dated_leave_allowed"):
if rec.past_dated_leave_allowed == value["past_dated_leave_allowed"] and rec.past_dated_leave_allowed:
if value.has_key("override_paid_leave_to_unpaid"):
if rec.override_paid_leave_to_unpaid == value["override_paid_leave_to_unpaid"] and rec.override_paid_leave_to_unpaid:
raise UserError(_('This type of leave already exist in the leave rules !'))
ç ondition因爲沒有重複的條目工作正常,但獨特的形式不保存信息
的錯誤是 - 如何使用SQL約束
AttributeError: 'NoneType' object has no attribute 'id'
由於它的工作。 。! –