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:
- CRM
- e-Commerce
- Contabilitate
- Inventar
- PoS
- Project
- MRP
Această întrebare a fost marcată
4674
Vizualizări
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Înscrie-teRelated Posts | Răspunsuri | Vizualizări | Activitate | |
---|---|---|---|---|
|
0
apr. 24
|
2082 | ||
|
0
dec. 19
|
4790 | ||
|
5
dec. 19
|
3847 | ||
|
0
aug. 19
|
4 | ||
|
5
aug. 19
|
2916 |