[UPD] odex_benefit: sequence should be unique for mother, replacement, family member

This commit is contained in:
Samir Ladoui 2025-02-13 11:47:36 +01:00
parent 40a050cce5
commit d7bb819495
3 changed files with 29 additions and 19 deletions

View File

@ -75,12 +75,4 @@
<field eval="False" name="company_id"/>
<field name="padding">4</field>
</record>
<!-- Sequence for Education Status -->
<record id="seq_education_status" model="ir.sequence">
<field name="name">Education Status Sequence</field>
<field name="code">education.status</field>
<field name="prefix">EDU/</field>
<field name="padding">4</field>
<field name="company_id" eval="False"/>
</record>
</odoo>

View File

@ -16,6 +16,7 @@ class EducationStatus(models.Model):
copy=False,
index=True
)
education_status_type = fields.Selection(
selection=[
('current', 'Current'),
@ -58,11 +59,6 @@ class EducationStatus(models.Model):
percentage = fields.Float(string="Percentage%")
specialization_ids = fields.Many2one('specialization.specialization', string='Specialization')
# weak_study = fields.Many2many(
# 'study.material',
# relation='education_status_weak_study_rel',
# string='Weak Study'
# )
weak_course_ids = fields.One2many('weak.course', 'education_status_id')
@ -89,7 +85,33 @@ class EducationStatus(models.Model):
@api.model
def create(self, vals):
# Check if the user is creating a 'current' education status
# Determine the prefix based on the related field
prefix = 'EDU/'
relation_field = False
if vals.get('mother_grant_benefit_id'):
prefix = 'EDUM/'
relation_field = 'mother_grant_benefit_id'
elif vals.get('replacement_grant_benefit_id'):
prefix = 'EDUR/'
relation_field = 'replacement_grant_benefit_id'
elif vals.get('family_member_id'):
prefix = 'EDUF/'
relation_field = 'family_member_id'
# Build domain filter to count records for the same category
domain = [('name', 'like', prefix)]
if relation_field and vals.get(relation_field):
domain.append((relation_field, '=', vals.get(relation_field)))
# Get the count of existing records with the same prefix & relation ID
existing_count = self.search_count(domain) + 1
formatted_number = str(existing_count).zfill(4) # Format as 4-digit number
# Assign computed sequence name
vals['name'] = f"{prefix}{formatted_number}"
# Ensure only one 'current' education status exists
relation_id = vals.get('mother_grant_benefit_id', vals.get('replacement_grant_benefit_id', vals.get('family_member_id', False)))
if not self.env.context.get('skip_current_check') and vals.get('education_status_type') == 'current' and relation_id:
existing_current = self.search([
@ -103,8 +125,4 @@ class EducationStatus(models.Model):
if existing_current:
existing_current.education_status_type = 'previous'
# Set sequence for 'name' field
if vals.get('name', '/') == '/':
vals['name'] = self.env['ir.sequence'].next_by_code('education.status') or '/'
return super(EducationStatus, self).create(vals)

View File

@ -40,7 +40,7 @@
<!-- Title -->
<div class="oe_title">
<h1>
<field name="name" readonly="1"/>
<field name="name"/>
</h1>
</div>