I am trying to build a condition where the store has a s_start_date and s_end_date.
The employee working for the store also has a start_date and end_date.
Let's assume:
Case1------------
store_name: store 1
s_start_date = 12/01/2019, s_end_date = 12/30/2019
Employee_name: Emp1
start_date = 12/01/2019, end_date = 12/20/2019 #Expected
start_date = 11/01/2019, end_date = 01/20/2020 #It should throw an error as the dates are out of store contract.
case 2-----------------
The condition here is only one employee is needed at a single store
store_name: store 1
s_start_date = 12/01/2019, s_end_date = 12/30/2019
Employee_name: Emp1
start_date = 12/01/2019, end_date = 12/20/2019 #Expected
Employee_name: Emp2
start_date = 12/21/2019, end_date = 12/30/2019 #Expected
start_date = 12/05/2019, end_date = 12/17/2019 #Should throw an error saying that employee already exist for the time frame
Please find the attached code for your reference .
class wv_location(models.Model):
_name= "wv.location"
storel_name = fields.Char(string="Store Name")
s_start_date = fields.Date('Store Start Date', required=True, index=True)
s_end_date = fields.Date('Store End Date', constrains="_check_date")
emp_loc_id = fields.One2many('wv.emp.location', 'employee_loc_id', string="Employees")
@api.constrains('s_start_date','s_end_date')
def _check_date(self):
if self.s_start_date > self.s_end_date:
raise ValidationError('End date must be greater than start date')
------------------------------------------------------------------------------
class wv_emp_location(models.Model):
_name = "wv.emp.location"
employee_id = fields.Many2one('hr.employee', 'Employee', ondelete='cascade')
employee_loc_id = fields.Many2one('wv.location', 'Employee Location', ondelete='cascade')
start_date = fields.Date('Start Date', tracking=True, default=fields.Date.context_today, constrains="_check_unique_date")
end_date = fields.Date('End Date', tracking=True, default=fields.Date.context_today, constrains="_check_date")
@api.constrains('start_date','end_date')
def _check_date(self):
if self.start_date > self.end_date:
raise ValidationError('End date must be greater than start date')
--------------------------------------------------------------------------------
Please let me know if you need more information on this.
Thank you
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
4662
มุมมอง
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อRelated Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
---|---|---|---|---|
|
0
เม.ย. 24
|
2079 | ||
|
0
ธ.ค. 19
|
4785 | ||
|
5
ธ.ค. 19
|
3846 | ||
|
0
ส.ค. 19
|
4 | ||
|
5
ส.ค. 19
|
2914 |