home restoration service

This commit is contained in:
eman 2024-11-04 01:17:13 +02:00
parent 002e7535c4
commit 43b5efb7e2
9 changed files with 70 additions and 5 deletions

View File

@ -29,6 +29,7 @@ class ServiceRequest(models.Model):
estimated_rent_amount = fields.Float(string="Estimated Rent Amount",compute="_get_estimated_rent_amount")
paid_rent_amount = fields.Float(string="Paid Rent Amount",compute="_get_paid_rent_amount")
service_type = fields.Selection([('rent', 'Rent')],string='Service Type',related='service_cat.service_type')
# is_alternative_housing = fields.Boolean(string='Is Alternative Housing?')
rent_contract_number = fields.Char(string="Rent Contract Number",related ="family_id.contract_num")
rent_start_date = fields.Date(string='Rent Start Date',related ="family_id.rent_start_date")
rent_end_date = fields.Date(string='Rent End Date' ,related ="family_id.rent_end_date")

View File

@ -81,6 +81,7 @@
<field name="member_rent_start_date" attrs="{'invisible':[('benefit_type','!=','member')]}"/>
<field name="member_rent_end_date" attrs="{'invisible':[('benefit_type','!=','member')]}"/>
<field name="member_rent_attachment" widget="many2many_attachment_preview" attrs="{'invisible':[('benefit_type','!=','member')]}"/>
<!-- <field name="is_alternative_housing" widget="boolean_toggle"/>-->
</group>
<group attrs="{'invisible':[('benefit_type','!=','family')]}">
<separator string="Rent Amounts" colspan="2"/>

View File

@ -10,5 +10,6 @@
'depends': ['odex_benefit'],
'data': ['views/services_settings_inherit.xml',
'views/project_project_inherit.xml',
'views/service_request_inherit.xml',
],
}

View File

@ -8,6 +8,18 @@ class ProjectProjectInherit(models.Model):
restoration_max_amount = fields.Float(string='Restoration Max Amount')
has_money_field_is_appearance = fields.Boolean(string='Has money Field is appearance?')
has_money_to_pay_first_payment = fields.Boolean(string='Has money to pay first payment?')
is_family_need_evacuate = fields.Boolean(string='Is family need evacuate?')
service_type = fields.Selection([('rent', 'Rent'),('home_restoration', 'Home Restoration'),('alternative_housing', 'Alternative Housing'),('home_maintenance','Home Maintenance')],string='Service Type')
def create_alternative_housing_request(self):
for rec in self:
alternative_housing_request = self.env['service.request'].create(
{
'family_id': self.env['grant.benefit'].search([('partner_id','=',rec.beneficiary_id.id)]).id,
'benefit_type':'family',
'service_cat': self.env['services.settings'].search([('service_type','=','alternative_housing')],limit=1).id,
}
)
alternative_housing_request.write({
'main_service_category':alternative_housing_request.service_cat.parent_service.parent_service,
'sub_service_category' : alternative_housing_request.service_cat.parent_service,
})

View File

@ -1,23 +1,51 @@
from odoo import fields, models, api, _
from odoo.exceptions import UserError, ValidationError
from datetime import timedelta
class ServiceRequestInherit(models.Model):
_inherit = 'service.request'
project_id = fields.Many2one('project.project',srting='Project')
rent_period = fields.Integer('Rent Period')
def action_second_approve(self):
super(ServiceRequestInherit, self).action_second_approve()
for rec in self:
if rec.service_cat.project_create:
self.env['project.project'].create(
project = self.env['project.project'].create(
{
'name': (_('Home Restoration Service')) +"/"+ rec.family_id.name +"/"+ rec.family_id.code,
'partner_id': rec.service_producer_id.id,
'beneficiary_id': rec.family_id.partner_id.id,
# 'category_id' : rec.service_cat.id,
'category_id' : rec.service_cat.category_id,
'requested_service_amount' : rec.requested_service_amount,
'restoration_max_amount' : rec.restoration_max_amount,
'has_money_field_is_appearance': rec.has_money_field_is_appearance,
'has_money_to_pay_first_payment' : rec.has_money_to_pay_first_payment,
'service_type' : rec.service_cat.service_type,
}
)
)
rec.project_id = project
@api.onchange('requested_service_amount', 'benefit_type', 'date','rent_period')
def onchange_requested_service_amount(self):
for rec in self:
today = fields.Date.today()
date_before_year = today - timedelta(days=365)
if rec.requested_service_amount and rec.benefit_type == 'member':
max_requested_amount = rec.service_cat.max_amount_for_student
if rec.requested_service_amount > max_requested_amount:
raise UserError(_("You Cannot request More than %s") % max_requested_amount)
if rec.requested_service_amount and rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_maintenance':
max_requested_amount = rec.service_cat.max_maintenance_amount
if rec.requested_service_amount > max_requested_amount:
raise UserError(_("You Cannot request More than %s") % max_requested_amount)
if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_maintenance':
if self.search([('date', '>', date_before_year), ('family_id', '=', rec.family_id.id)]):
raise UserError(_("You Cannot request this service twice in same year"))
if rec.benefit_type == 'family' and rec.service_cat.service_type == 'alternative_housing':
if rec.requested_service_amount > rec.service_cat.rent_amount_for_alternative_housing:
raise UserError(_("You Cannot request amount more than %s")%rec.service_cat.rent_amount_for_alternative_housing)
elif rec.rent_period > rec.service_cat.rent_period :
raise UserError(_("You Cannot request this service for perion more than %s")%rec.service_cat.rent_period)

View File

@ -5,3 +5,4 @@ class ServiceSettingsInherit(models.Model):
_inherit = 'services.settings'
project_create = fields.Boolean(string='Project Create?')
category_id = fields.Many2one('project.category', string='Project Category')

View File

@ -14,9 +14,13 @@
<field name="restoration_max_amount"/>
<field name="has_money_field_is_appearance" invisible="1"/>
<field name="has_money_to_pay_first_payment" widget="boolean_toggle" attrs="{'invisible':[('has_money_field_is_appearance', '=', False)]}"/>
<field name="is_family_need_evacuate"/>
</group>
</page>
</xpath>
<xpath expr="//header" position="inside">
<button name="create_alternative_housing_request" class="btn-primary" string="Create Alternative Housing Request" type="object" attrs="{'invisible':['|',('service_type', '!=', 'home_restoration'),('is_family_need_evacuate','=',False)]}"/>
</xpath>
</field>
</record>
</data>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="service_request_inherit_view_form" model="ir.ui.view">
<field name="name">service.request.form</field>
<field name="model">service.request</field>
<field name="inherit_id" ref="odex_benefit.service_request_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='requested_service_amount']" position="after">
<field name="rent_period" required="1"/>
<field name="project_id" readonly="1"/>
</xpath>
</field>
</record>
</data>
</odoo>

View File

@ -8,6 +8,7 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='service_type']" position="before">
<field name="project_create"/>
<field name="category_id" attrs="{'invisible': [('project_create', '=', False)]}"/>
</xpath>
</field>
</record>