Complete building house

This commit is contained in:
eman 2024-11-13 01:55:30 +02:00
parent d541b9bf58
commit 8f7aece19c
9 changed files with 249 additions and 54 deletions

View File

@ -130,11 +130,11 @@ class ConfirmBenefitExpense(models.Model):
# rec.family_ids = self.env['grant.benefit'].search(base_domain).ids
rec.journal_domain_ids = self.env['account.journal'].search(journal_domain)
def unlink(self):
for rec in self:
if rec.state not in ['draft']:
raise UserError(_('This record can only be deleted in draft state.'))
return super(ConfirmBenefitExpense, self).unlink()
# def unlink(self):
# for rec in self:
# if rec.state not in ['draft']:
# raise UserError(_('This record can only be deleted in draft state.'))
# return super(ConfirmBenefitExpense, self).unlink()
@api.depends('family_ids', 'expense_type')
def _get_family_monthly_values(self):
@ -260,7 +260,7 @@ class ConfirmBenefitExpense(models.Model):
# Define base domain for family selection
validation_setting = self.env["family.validation.setting"].search([], limit=1)
base_domain = [('state', 'in', ('second_approve', 'temporarily_suspend', 'suspend'))]
base_domain = [('state', 'in', ('second_approve', 'temporarily_suspended', 'suspended_first_approve'))]
if self.branch_custom_id:
base_domain.append(('branch_custom_id', '=', self.branch_custom_id.id))
min_income = validation_setting.benefit_category_ids.mapped('mini_income_amount')

View File

@ -24,12 +24,12 @@ class PaymentOrders(models.Model):
res.name = self.env['ir.sequence'].sudo().next_by_code('payment.orders.sequence') or _('New')
return res
@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
if self.env.user and self.env.user.id and self.env.user.has_group(
"odex_benefit.group_benefit_accountant_accept"):
args += [('accountant_id', '=', self.env.user.id)]
return super(PaymentOrders, self).search(args, offset, limit, order, count)
# @api.model
# def search(self, args, offset=0, limit=None, order=None, count=False):
# if self.env.user and self.env.user.id and self.env.user.has_group(
# "odex_benefit.group_benefit_accountant_accept"):
# args += [('accountant_id', '=', self.env.user.id)]
# return super(PaymentOrders, self).search(args, offset, limit, order, count)
def _get_total_moves(self):
for rec in self:

View File

@ -70,7 +70,6 @@ class ServiceRequest(models.Model):
accountant_id = fields.Many2one('res.users',string='Accountant',related='service_cat.accountant_id',readonly=False)
service_producer_id = fields.Many2one('res.partner',string='Service Producer',related='service_cat.service_producer_id')
is_service_producer = fields.Boolean(string='Is Service Producer?',related='service_cat.is_service_producer')
benefit_category_ids = fields.Many2many('benefit.category', string='Allowed Categories',related='')
# maintenance_items_id = fields.Many2one('home.maintenance.lines', string="Maintenance Items")
maintenance_items_ids = fields.One2many('home.maintenance.items','service_request_id', string="Maintenance Items",)
#Home restoration fields
@ -80,6 +79,10 @@ class ServiceRequest(models.Model):
payment_order_id = fields.Many2one('payment.orders',string='Payment Order')
is_payment_order_done = fields.Boolean(string='Is Payment Order Done?')
aid_amount = fields.Float(string='Aid Amount',compute='_get_aid_amount')
# this field for complete building house service
has_money_for_payment_is_appearance = fields.Boolean(string='Has money Field is appearance?',compute='_get_money_for_payment_is_appearance')
has_money_for_payment = fields.Selection([('yes', 'Yes'), ('no', 'No')], string='Has money for payment?')
max_complete_building_house_amount = fields.Float(string='Max Complete Building House Amount',related='service_cat.max_complete_building_house_amount')
state = fields.Selection([
('draft', 'Draft'),
('researcher', 'Researcher'),
@ -90,12 +93,13 @@ class ServiceRequest(models.Model):
('refused', 'Refused'),
], string='state', default="draft", tracking=True)
@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
if self.env.user and self.env.user.id and self.env.user.has_group(
"odex_benefit.group_benefit_accountant_accept"):
args += [('accountant_id', '=', self.env.user.id)]
return super(ServiceRequest, self).search(args, offset, limit, order, count)
# @api.model
# def search(self, args, offset=0, limit=None, order=None, count=False):
# if self.env.user and self.env.user.id and self.env.user.has_group(
# "odex_benefit.group_benefit_accountant_accept"):
# args += [('accountant_id', '=', self.env.user.id)]
# return super(ServiceRequest, self).search(args, offset, limit, order, count)
@api.model
def create(self, vals):
@ -217,8 +221,8 @@ class ServiceRequest(models.Model):
for line in self.service_cat.home_restoration_lines:
if line.benefit_category_id == self.family_category:
self.restoration_max_amount = line.max_amount
else:
self.restoration_max_amount = 0.0
# else:
# self.restoration_max_amount = 0.0
@api.depends('requested_service_amount', 'restoration_max_amount')
def _get_money_field_is_appearance(self):
for rec in self:
@ -227,6 +231,14 @@ class ServiceRequest(models.Model):
else:
rec.has_money_field_is_appearance = False
@api.depends('requested_service_amount', 'max_complete_building_house_amount')
def _get_money_for_payment_is_appearance(self):
for rec in self:
if rec.requested_service_amount and rec.max_complete_building_house_amount and rec.requested_service_amount > rec.max_complete_building_house_amount:
rec.has_money_for_payment_is_appearance = True
else:
rec.has_money_for_payment_is_appearance = False
def _get_aid_amount(self):
for rec in self:
if rec.service_type == 'rent':
@ -281,22 +293,107 @@ class ServiceRequest(models.Model):
new_month_before_rent_payment_date = rec.new_rent_payment_date - timedelta(days=30)
if today_date > new_month_before_rent_payment_date:
raise UserError(_("You Should request At least a month ago rent payment date"))
@api.onchange('requested_service_amount','benefit_type','date')
# @api.onchange('requested_service_amount','benefit_type','date')
# def onchange_requested_service_amount(self):
# res = {}
# 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 == 'complete_building_house':
# if self.search([('family_id','=',rec.family_id.id),('service_type','=','complete_building_house'),('id','!=',self._origin.id)]):
# self.benefit_type = False
# res['warning'] = {'title': _('ValidationError'),
# 'message': _("You Cannot request this service twice")}
# return res
@api.onchange('requested_service_amount', 'benefit_type', 'date','service_cat')
def onchange_requested_service_amount(self):
res = {}
today = fields.Date.today()
date_before_year = today - timedelta(days=365)
date_before_ten_years = today - timedelta(days=3650)
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':
# Validation for 'member' benefit type
if rec.benefit_type == 'member' and rec.requested_service_amount:
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':
self.benefit_type = False
res['warning'] = {'title': _('ValidationError'),
'message': _("You cannot request more than %s") % max_requested_amount}
return res
# Validation for 'family' benefit type with 'home_maintenance'
if 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"))
self.benefit_type = False
res['warning'] = {'title': _('ValidationError'),
'message': _("You cannot request more than %s") % max_requested_amount}
return res
# Prevent multiple 'home_maintenance' requests within the same year
existing_request_maintenance = self.search([
('date', '>', date_before_year),
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'home_maintenance'), ('id', '!=', self._origin.id)
], limit=1)
if existing_request_maintenance:
raise UserError(_("You cannot request this service more than once a year."))
existing_request_restoration = self.search([
('date', '>', date_before_year),
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id)
], limit=1)
if existing_request_restoration:
raise UserError(_("You cannot request this service with restoration service in the same year."))
# Validation for 'family' benefit type with 'home_restoration'
if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_restoration':
# Prevent multiple 'home_maintenance' requests within the same year
existing_request_restoration = self.search([
('date', '>', date_before_ten_years),
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id)
], limit=1)
if existing_request_restoration:
raise UserError(_("You cannot request this service more than once a ten years."))
existing_request_maintenance = self.search([
('date', '>', date_before_year),
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'home_maintenance')
], limit=1)
if existing_request_maintenance:
raise UserError(
_("You cannot request this service with maintenance service in the same year."))
# Validation for 'family' benefit type with 'complete_building_house' service type
if rec.benefit_type == 'family' and rec.service_cat.service_type == 'complete_building_house':
# Check for existing request of the same type
existing_request = self.search([
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'complete_building_house'),
], limit=1)
if existing_request:
raise UserError(
_("You Cannot request this service twice"))
existing_request_restoration = self.search([
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'home_restoration'),
], limit=1)
if existing_request_restoration:
raise UserError(
_("You Cannot request this service and home restoration twice"))
@api.onchange('member_id')
def onchange_member_id(self):
for rec in self:
@ -370,4 +467,4 @@ class ServiceRequest(models.Model):
'view_mode': 'form',
'target': 'new',
'context': {'default_service_ids': ids}
}
}

View File

@ -11,7 +11,8 @@ class ServicesSettings(models.Model):
is_service_producer = fields.Boolean(string='Is Service Producer?')
service_producer_id = fields.Many2one('res.partner',string='Service Producer')
is_this_service_for_student = fields.Boolean(string='Is Service For Student?')
service_type = fields.Selection([('rent', 'Rent'),('home_restoration', 'Home Restoration'),('alternative_housing', 'Alternative Housing'),('home_maintenance','Home Maintenance')],string='Service Type')
service_type = fields.Selection([('rent', 'Rent'),('home_restoration', 'Home Restoration'),('alternative_housing', 'Alternative Housing'),('home_maintenance','Home Maintenance')
,('complete_building_house','Complete Building House')],string='Service Type')
max_amount_for_student = fields.Float(string='Max Amount for Student')
raise_amount_for_orphan = fields.Float(string='Raise Amount For Orphan')
rent_lines = fields.One2many('rent.lines','services_settings_id')
@ -25,6 +26,8 @@ class ServicesSettings(models.Model):
max_maintenance_amount = fields.Float(string='Max Maintenance Amount')
account_id = fields.Many2one('account.account',string='Expenses Account',domain="[('user_type_id.id','=',15)]")
accountant_id = fields.Many2one('res.users',string='Accountant')
#Fields for Complete Building House
max_complete_building_house_amount = fields.Float(string='Max Complete Building House Amount')
class RentLines(models.Model):
_name = 'rent.lines'

View File

@ -160,6 +160,13 @@
<field name="has_money_to_pay_first_payment" attrs="{'invisible':[('has_money_field_is_appearance', '=', False)],'required':[('has_money_field_is_appearance', '=', True)]}"/>
</group>
</page>
<page string="Complete Building House" attrs="{'invisible':[('service_type', '!=', 'complete_building_house')]}">
<group>
<field name="max_complete_building_house_amount"/>
<field name="has_money_for_payment" attrs="{'invisible':[('has_money_for_payment_is_appearance', '=', False)],'required':[('has_money_for_payment_is_appearance', '=', True)]}"/>
<field name="has_money_for_payment_is_appearance" invisible="1"/>
</group>
</page>
</notebook>
</sheet>
<div class="oe_chatter">

View File

@ -69,12 +69,16 @@
<field name="maintenance_name"/>
</tree>
</field>
<!-- <group>-->
<group>
<field name="benefit_category_ids" widget="many2many_tags"/>
<field name="max_maintenance_amount"/>
</group>
<!-- </group>-->
<group>
<field name="benefit_category_ids" widget="many2many_tags"/>
<field name="max_maintenance_amount"/>
</group>
</page>
<page string="Complete Building House Settings" attrs="{'invisible':[('service_type','!=','complete_building_house')]}">
<group>
<field name="benefit_category_ids" widget="many2many_tags"/>
<field name="max_complete_building_house_amount"/>
</group>
</page>
</notebook>
</sheet>

View File

@ -4,12 +4,20 @@ class ProjectProjectInherit(models.Model):
_inherit = 'project.project'
#Fields for 'Home restoration' service and 'alternative_housing' service
requested_service_amount = fields.Float(string="Requested Service Amount")
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')
#Fields for 'complete building house' service
max_complete_building_house_amount = fields.Float(string='Max Complete Building House Amount')
has_money_for_payment_is_appearance = fields.Boolean(string='Has money Field is appearance?')
has_money_for_payment = fields.Selection([('yes', 'Yes'), ('no', 'No')], string='Has money for payment?')
service_type = fields.Selection(
[('rent', 'Rent'), ('home_restoration', 'Home Restoration'), ('alternative_housing', 'Alternative Housing'),
('home_maintenance', 'Home Maintenance')
, ('complete_building_house', 'Complete Building House')], string='Service Type')
service_requests_count = fields.Integer(
string="Service Requests",
compute='_compute_service_requests_count'

View File

@ -15,7 +15,7 @@ class ServiceRequestInherit(models.Model):
if rec.service_cat.project_create:
project = self.env['project.project'].create(
{
'name': (_('Home Restoration Service')) +"/"+ rec.family_id.name +"/"+ rec.family_id.code,
'name': (_('%s')%rec.service_cat.service_type) +"/"+ 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.category_id.id,
@ -24,28 +24,95 @@ class ServiceRequestInherit(models.Model):
'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,
'max_complete_building_house_amount' : rec.max_complete_building_house_amount,
'has_money_for_payment_is_appearance' : rec.has_money_for_payment_is_appearance,
'has_money_for_payment' : rec.has_money_for_payment,
}
)
rec.project_id = project
@api.onchange('requested_service_amount', 'benefit_type', 'date','rent_period')
@api.onchange('requested_service_amount', 'benefit_type', 'date', 'service_cat')
def onchange_requested_service_amount(self):
res = {}
today = fields.Date.today()
date_before_year = today - timedelta(days=365)
date_before_ten_years = today - timedelta(days=3650)
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':
# Validation for 'member' benefit type
if rec.benefit_type == 'member' and rec.requested_service_amount:
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':
self.benefit_type = False
res['warning'] = {'title': _('ValidationError'),
'message': _("You cannot request more than %s") % max_requested_amount}
return res
# Validation for 'family' benefit type with 'home_maintenance'
if 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"))
self.benefit_type = False
res['warning'] = {'title': _('ValidationError'),
'message': _("You cannot request more than %s") % max_requested_amount}
return res
# Prevent multiple 'home_maintenance' requests within the same year
existing_request_maintenance = self.search([
('date', '>', date_before_year),
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'home_maintenance'), ('id', '!=', self._origin.id)
], limit=1)
if existing_request_maintenance:
raise UserError(_("You cannot request this service more than once a year."))
existing_request_restoration = self.search([
('date', '>', date_before_year),
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id)
], limit=1)
if existing_request_restoration:
raise UserError(
_("You cannot request this service with restoration service in the same year."))
# Validation for 'family' benefit type with 'home_restoration'
if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_restoration':
# Prevent multiple 'home_maintenance' requests within the same year
existing_request_restoration = self.search([
('date', '>', date_before_ten_years),
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id)
], limit=1)
if existing_request_restoration:
raise UserError(_("You cannot request this service more than once a ten years."))
existing_request_maintenance = self.search([
('date', '>', date_before_year),
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'home_maintenance')
], limit=1)
if existing_request_maintenance:
raise UserError(
_("You cannot request this service with maintenance service in the same year."))
# Validation for 'family' benefit type with 'complete_building_house' service type
if rec.benefit_type == 'family' and rec.service_cat.service_type == 'complete_building_house':
# Check for existing request of the same type
existing_request = self.search([
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'complete_building_house'),
], limit=1)
if existing_request:
raise UserError(
_("You Cannot request this service twice"))
existing_request_restoration = self.search([
('family_id', '=', rec.family_id.id),
('service_cat.service_type', '=', 'home_restoration'),
], limit=1)
if existing_request_restoration:
raise UserError(
_("You Cannot request this service and home restoration twice"))
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)
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 period more than %s") % rec.service_cat.rent_period)

View File

@ -23,6 +23,15 @@
<field name="is_family_need_evacuate" groups="project_base.group_project_department_manager"/>
</group>
</page>
<page string="Complete Building House Service" attrs="{'invisible':[('service_type', '!=', 'complete_building_house')]}">
<group>
<field name="service_type" readonly="1" force_save="1"/>
<field name="requested_service_amount" readonly="1" force_save="1"/>
<field name="max_complete_building_house_amount" readonly="1" force_save="1"/>
<field name="has_money_for_payment_is_appearance" invisible="1"/>
<field name="has_money_for_payment" attrs="{'invisible':[('has_money_for_payment_is_appearance', '=', False)]}" readonly="1" force_save="1"/>
</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)]}"/>