Recruiting Driver Service

This commit is contained in:
eman 2024-11-21 11:34:05 +02:00
parent ed3bfa30f4
commit 27e2cb8b63
2 changed files with 59 additions and 19 deletions

View File

@ -135,37 +135,68 @@ class ServiceRequest(models.Model):
@api.model
def create(self, vals):
# Define the list of fields to check
new_rent_fields = [
'new_rent_contract_number',
'new_rent_start_date',
'new_rent_end_date',
'new_rent_amount',
'new_payment_type',
'new_rent_attachment'
]
res = super(ServiceRequest, self).create(vals)
if not res.name or res.name == _('New'):
res.name = self.env['ir.sequence'].sudo().next_by_code('service.request.sequence') or _('New')
# Check if any of the specified fields are present in vals
if any(field in vals for field in new_rent_fields):
if res.family_id:
# Prepare values for family_id write
update_values = {}
if 'new_rent_contract_number' in vals:
update_values['contract_num'] = vals['new_rent_contract_number']
if 'new_rent_start_date' in vals:
update_values['rent_start_date'] = vals['new_rent_start_date']
if 'new_rent_end_date' in vals:
update_values['rent_end_date'] = vals['new_rent_end_date']
if 'new_rent_amount' in vals:
update_values['rent_amount'] = vals['new_rent_amount']
if 'new_payment_type' in vals:
update_values['payment_type'] = vals['new_payment_type']
if 'new_rent_attachment' in vals:
update_values['rent_attachment'] = vals['new_rent_attachment']
# Write updates to the related family_id
res.family_id.write(update_values)
return res
def write(self, vals):
# Define the list of fields you want to check
new_rent_fields = ['new_rent_contract_number', 'new_rent_start_date', 'new_rent_end_date', 'new_rent_amount',
'new_payment_type', 'new_rent_attachment']
# Call the original write method
result = super(ServiceRequest, self).write(vals)
# Prepare values for family_id write, only if any of the fields are present in vals
update_values = {}
if any(field in vals for field in new_rent_fields):
# Use `get` to avoid KeyError if a field is missing in vals
update_values = {
'contract_num': vals.get('new_rent_contract_number'),
'rent_start_date': vals.get('new_rent_start_date'),
'rent_end_date': vals.get('new_rent_end_date'),
'rent_amount': vals.get('new_rent_amount'),
'payment_type': vals.get('new_payment_type'),
}
for record in self:
# Ensure family_id exists before proceeding
if record.family_id:
# Prepare values for family_id write
update_values = {}
# Add fields to update_values only if they exist in vals
if 'new_rent_contract_number' in vals:
update_values['contract_num'] = vals['new_rent_contract_number']
if 'new_rent_start_date' in vals:
update_values['rent_start_date'] = vals['new_rent_start_date']
if 'new_rent_end_date' in vals:
update_values['rent_end_date'] = vals['new_rent_end_date']
if 'new_rent_amount' in vals:
update_values['rent_amount'] = vals['new_rent_amount']
if 'new_payment_type' in vals:
update_values['payment_type'] = vals['new_payment_type']
if 'new_rent_attachment' in vals:
update_values['rent_attachment'] = vals['new_rent_attachment']
# Check if 'new_rent_attachment' exists in vals before updating
if 'new_rent_attachment' in vals:
update_values['rent_attachment'] = vals['new_rent_attachment']
# Write the prepared update values to `family_id`
self.family_id.write(update_values)
# Write the prepared update values to `family_id`
record.family_id.write(update_values)
return result

View File

@ -73,7 +73,15 @@
<field name="main_service_category" attrs="{'readonly':[('state','not in',['draft','researcher','send_request'])]}" required="1"/>
<field name="sub_service_category" attrs="{'readonly':[('state','not in',['draft','researcher','send_request'])]}" required="1"/>
<field name="service_cat" attrs="{'readonly':[('state','not in',['draft','researcher','send_request'])]}" required="1"/>
<field name="requested_service_amount" attrs="{'readonly':['|',('state','not in',['draft','researcher','send_request']),('service_type','=','home_furnishing')]}" force_save="1" required="1"/>
<field name="requested_service_amount" attrs="{'readonly': ['|',
'|',
'&amp;',
('state', 'not in', ['draft', 'researcher', 'send_request']),
('service_type', '!=', 'electrical_devices'),
'&amp;',
('state', 'not in', ['draft', 'researcher', 'send_request', 'first_approve', 'second_approve', 'accounting_approve']),
('service_type', '=', 'electrical_devices'),
('service_type', '=', 'home_furnishing')]}" force_save="1" required="1"/>
<field name="max_electricity_bill_amount" readonly="1" force_save="1" attrs="{'invisible':[('service_type','!=','electricity_bill')]}"/>
<field name="max_water_bill_amount" readonly="1" force_save="1" attrs="{'invisible':[('service_type','!=','water_bill')]}"/>
<field name="aid_amount" invisible="1"/>
@ -241,6 +249,7 @@
<field name="sub_service_category"/>
<field name="service_cat"/>
<field name="payment_order_id" groups="odex_benefit.group_benefit_accounting_accept"/>
<field name="vendor_bill" groups="odex_benefit.group_benefit_accounting_accept"/>
<field name="state" widget="badge" decoration-success="state in ['second_approve']" decoration-muted="state == 'draft'"
decoration-danger="state in ['refused']" decoration-info="state in ['first_approve','send_request']" decoration-warning="state in ['researcher']"/>
</tree>