tasks
This commit is contained in:
parent
a893e0be5a
commit
37b5992bd2
|
|
@ -7,6 +7,7 @@
|
|||
<field name="email_from">
|
||||
<![CDATA[${user.company_id.name} <${(user.company_id.email or user.partner_id.email or 'noreply@localhost')|safe}>]]></field>
|
||||
<field name="email_to">${(object.email and object.researcher_id.employee_id[0].work_email)|safe}</field>
|
||||
<field name="email_cc">${(object.email)|safe}</field>
|
||||
<field name="subject"> Attachment Expiration </field>
|
||||
<field name="body_html" type="html">
|
||||
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"><tr><td align="center">
|
||||
|
|
|
|||
|
|
@ -23,21 +23,33 @@
|
|||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">days</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field name="nextcall" eval="(DateTime.today() + relativedelta(hours=0, minutes=0)).strftime('%Y-%m-%d %H:%M:%S')"/>
|
||||
<field name="doall" eval="False"/>
|
||||
<field name="model_id" ref="model_grant_benefit"/>
|
||||
<field name="code">model.send_expiry_date_notification()</field>
|
||||
<field name="state">code</field>
|
||||
</record>
|
||||
<record id="ir_cron_auto_suspend" model="ir.cron">
|
||||
<field name="name">Automatic Suspend</field>
|
||||
<record id="ir_cron_update_data_auto" model="ir.cron">
|
||||
<field name="name">Update Data Auto (Daily)</field>
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">days</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field name="nextcall" eval="(DateTime.today() + relativedelta(hours=0, minutes=0)).strftime('%Y-%m-%d 00:00:00')"/>
|
||||
<field name="doall" eval="False"/>
|
||||
<field name="model_id" ref="model_grant_benefit"/>
|
||||
<field name="code">model.action_auto_suspend()</field>
|
||||
<field name="code">model.update_data_automatically()</field>
|
||||
<field name="state">code</field>
|
||||
</record>
|
||||
<!-- <record id="ir_cron_auto_suspend" model="ir.cron">-->
|
||||
<!-- <field name="name">Automatic Suspend</field>-->
|
||||
<!-- <field name="interval_number">1</field>-->
|
||||
<!-- <field name="interval_type">days</field>-->
|
||||
<!-- <field name="numbercall">-1</field>-->
|
||||
<!-- <field name="doall" eval="False"/>-->
|
||||
<!-- <field name="model_id" ref="model_grant_benefit"/>-->
|
||||
<!-- <field name="code">model.action_auto_suspend()</field>-->
|
||||
<!-- <field name="state">code</field>-->
|
||||
<!-- </record>-->
|
||||
<!-- <!– Cron for send notification for expiry date attachment for members–>-->
|
||||
<!-- <record id="members_send_notification" model="ir.cron">-->
|
||||
<!-- <field name="name">Notification: Expiry date Attachment</field>-->
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class GrantBenefitProfile(models.Model):
|
|||
name_in_bank = fields.Char()
|
||||
family_bank = fields.Many2one('res.partner.bank')
|
||||
acc_number = fields.Char('Account Number', required=True)
|
||||
account_holder = fields.Many2one('res.partner', 'Account Holder', ondelete='cascade', index=True, required=True)
|
||||
acc_holder_name = fields.Char('Account Holder Name', required=True)
|
||||
bank_id = fields.Many2one("res.bank",string='Bank',required = True)
|
||||
orphan_status = fields.Selection(
|
||||
selection=[('father', 'Father-Orphan'), ('mother', 'Mother-Orphan'), ('parent', 'Parent-Orphan'), ],
|
||||
|
|
@ -409,6 +409,7 @@ class GrantBenefitProfile(models.Model):
|
|||
suspend_type = fields.Selection(
|
||||
selection=[('temporarily_suspend', 'Temporarily Suspended'), ('suspend', 'Suspend')], string="Suspend Type")
|
||||
suspend_method = fields.Selection(selection=[('manual', 'Manual'), ('auto', 'Auto')], string="Suspend Method")
|
||||
sponsor_id = fields.Many2one('res.partner', string='Sponsor',domain="[('account_type','=','sponsor')]")
|
||||
|
||||
family_monthly_income = fields.Float(string="Family Monthly Income", compute='_get_family_monthly_values')
|
||||
family_monthly_meals = fields.Float(string="Family Monthly Meals", compute='_get_family_monthly_values')
|
||||
|
|
@ -739,6 +740,19 @@ class GrantBenefitProfile(models.Model):
|
|||
|
||||
# @api.multi
|
||||
def action_edit_info(self):
|
||||
# bank_val = {
|
||||
# 'acc_number': self.acc_number,
|
||||
# 'acc_holder_name': self.acc_holder_name,
|
||||
# 'bank_id': self.bank_id.id,
|
||||
# }
|
||||
# self.partner_id.write({
|
||||
# 'name': self.name,
|
||||
# 'email': self.email,
|
||||
# 'phone': self.phone,
|
||||
# 'account_type': 'family',
|
||||
# 'code': self.code,
|
||||
# 'bank_ids': [(0, 0, bank_val)]
|
||||
# })
|
||||
user = self.user_id
|
||||
if not user:
|
||||
user = self.env['res.users'].sudo().search(
|
||||
|
|
@ -792,6 +806,7 @@ class GrantBenefitProfile(models.Model):
|
|||
def action_suspend_refuse(self):
|
||||
for rec in self:
|
||||
rec.state = 'second_approve'
|
||||
rec.get_member_income()
|
||||
|
||||
# @api.multi
|
||||
def action_remove_from_black_list(self):
|
||||
|
|
@ -1168,7 +1183,7 @@ class GrantBenefitProfile(models.Model):
|
|||
ben.member_income = family_income / 3
|
||||
else:
|
||||
ben.member_income = 0
|
||||
|
||||
@api.depends("member_income")
|
||||
def get_benefit_category(self):
|
||||
for rec in self:
|
||||
if rec.member_income:
|
||||
|
|
@ -1247,7 +1262,7 @@ class GrantBenefitProfile(models.Model):
|
|||
def create_family_partner(self):
|
||||
bank_val = {
|
||||
'acc_number':self.acc_number,
|
||||
'partner_id':self.account_holder.id,
|
||||
'acc_holder_name':self.acc_holder_name,
|
||||
'bank_id':self.bank_id.id,
|
||||
}
|
||||
partner = self.env['res.partner'].create({
|
||||
|
|
@ -1278,7 +1293,7 @@ class GrantBenefitProfile(models.Model):
|
|||
def create_user(self):
|
||||
bank_val = {
|
||||
'acc_number':self.acc_number,
|
||||
'partner_id':self.account_holder.id,
|
||||
'acc_holder_name':self.acc_holder_name,
|
||||
'bank_id':self.bank_id.id,
|
||||
}
|
||||
for follower in self['message_follower_ids']:
|
||||
|
|
@ -1462,9 +1477,14 @@ class GrantBenefitProfile(models.Model):
|
|||
# 'researcher_team': rec.researcher_team.id,
|
||||
'state': 'draft'
|
||||
})
|
||||
def change_attachment_status(self):
|
||||
obj = self.env["grant.benefit"].search([])
|
||||
for attach in obj.attachment_ids:
|
||||
attach.get_status()
|
||||
|
||||
# Notifications
|
||||
def send_expiry_date_notification(self):
|
||||
self.change_attachment_status()
|
||||
obj = self.env["grant.benefit"].search([])
|
||||
for rec in obj:
|
||||
for attach in rec.attachment_ids:
|
||||
|
|
@ -1474,6 +1494,13 @@ class GrantBenefitProfile(models.Model):
|
|||
return
|
||||
template.with_context(lang=self.env.user.lang).send_mail(rec.id, force_send=True,
|
||||
raise_exception=False)
|
||||
#Update data automatically daily
|
||||
def update_data_automatically(self):
|
||||
obj = self.env["grant.benefit"].search([])
|
||||
for member in obj.member_ids:
|
||||
member._compute_get_age_date()
|
||||
member.check_member_status()
|
||||
self.action_auto_suspend()
|
||||
|
||||
|
||||
class BenefitFollowers(models.Model):
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class FamilyMemberProfile(models.Model):
|
|||
('girls_home','Girls Home'),('university_housing','University Housing'),('with_husband','With_husband'),('work_inside_saudi_arabia','Work Inside Saudi Arabia')], string="Member Location")
|
||||
# member_location = fields.Many2one('member.location', string="Member Location")
|
||||
birth_date = fields.Date(string="Birth Date")
|
||||
age = fields.Integer(string="Age", compute='_compute_get_age_date',search = '_search_age')
|
||||
age = fields.Integer(string="Age", compute='_compute_get_age_date',store=True)
|
||||
is_work = fields.Boolean('Is Work?')
|
||||
is_dead = fields.Boolean('Is Dead?')
|
||||
member_income = fields.Float('Member Income')
|
||||
|
|
@ -153,7 +153,7 @@ class FamilyMemberProfile(models.Model):
|
|||
member_status = fields.Selection(selection=[
|
||||
('benefit', 'Benefit'),
|
||||
('non_benefit', 'Non Benefit'),
|
||||
], string='Benefit Status', compute="check_member_status",default = False,search ='_search_member_status')
|
||||
], string='Benefit Status', compute="check_member_status",default = False,store=True)
|
||||
suspend_reason = fields.Many2one('suspend.reason', string='Suspend Reason')
|
||||
reason = fields.Text(string='Reason')
|
||||
suspend_description = fields.Text(string='Suspend Description')
|
||||
|
|
@ -163,47 +163,6 @@ class FamilyMemberProfile(models.Model):
|
|||
suspend_method = fields.Selection(selection=[('manual', 'Manual'), ('auto', 'Auto')], string="Suspend Method",default='auto')
|
||||
is_member_workflow = fields.Boolean('Is Member Workflow?')
|
||||
|
||||
def _search_age(self, operator, value):
|
||||
today = date.today()
|
||||
|
||||
# Calculate the date `value` years ago from today
|
||||
birthdate_exact = today.replace(year=today.year - value)
|
||||
|
||||
# Adjust for the leap year and the day/month when computing age
|
||||
if operator == '=':
|
||||
# Look for exact matches in terms of year, month, and day
|
||||
birthdate_lower = birthdate_exact.replace(year=birthdate_exact.year - 1)
|
||||
return [
|
||||
('birth_date', '>=', birthdate_lower),
|
||||
('birth_date', '<=', birthdate_exact),
|
||||
]
|
||||
elif operator == '>':
|
||||
# Return records where birth_date would give an age greater than `value`
|
||||
return [('birth_date', '<=', birthdate_exact)]
|
||||
elif operator == '<':
|
||||
# Return records where birth_date would give an age less than `value`
|
||||
return [('birth_date', '>=', birthdate_exact)]
|
||||
else:
|
||||
return []
|
||||
|
||||
def _search_member_status(self, operator, value):
|
||||
# Treat 'is' as equivalent to '='
|
||||
if operator == 'is':
|
||||
operator = '='
|
||||
|
||||
members = self.search([]) # Fetch all records
|
||||
matching_ids = []
|
||||
|
||||
for rec in members:
|
||||
rec.check_member_status() # Ensure the status is computed
|
||||
if operator == '=' and rec.member_status == value:
|
||||
matching_ids.append(rec.id)
|
||||
elif operator == '!=' and rec.member_status != value:
|
||||
matching_ids.append(rec.id)
|
||||
|
||||
return [('id', 'in', matching_ids)]
|
||||
|
||||
|
||||
def create_member_partner(self):
|
||||
self.partner_id.write({
|
||||
'email': self.email,
|
||||
|
|
|
|||
|
|
@ -11,17 +11,20 @@ class BenefitAttachment(models.Model):
|
|||
attach_status = fields.Selection(selection=[
|
||||
('valid', 'Valid'),
|
||||
('expired', 'Expired'),
|
||||
], string='Attach Status', required=True,compute = "get_status")
|
||||
], string='Attach Status', required=True,compute = "get_status",store=True)
|
||||
allow_days = fields.Integer(compute='get_allow_days',string='Allow Days')
|
||||
|
||||
@api.depends('expiration_date')
|
||||
def get_status(self):
|
||||
for rec in self:
|
||||
today = fields.Date.today()
|
||||
if rec.expiration_date and rec.expiration_date > today:
|
||||
rec.attach_status = 'valid'
|
||||
if rec.expiration_date:
|
||||
if rec.expiration_date and rec.expiration_date > today:
|
||||
rec.attach_status = 'valid'
|
||||
else:
|
||||
rec.attach_status = 'expired'
|
||||
else:
|
||||
rec.attach_status = 'expired'
|
||||
rec.attach_status = ''
|
||||
|
||||
@api.depends('attach_status')
|
||||
def get_allow_days(self):
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@
|
|||
states="suspended_first_approve"/>
|
||||
<button name="action_suspend_refuse" type="object"
|
||||
string="Suspend Refuse" class="oe_highlight"
|
||||
states="temporarily_suspended,suspended_first_approve"/>
|
||||
states="temporarily_suspended,suspended_first_approve,suspended_second_approve"/>
|
||||
<!-- <button name="action_remove_from_black_list" type="object"-->
|
||||
<!-- string="Remove from Black List" class="oe_highlight"-->
|
||||
<!-- states="black_list"-->
|
||||
|
|
@ -189,13 +189,14 @@
|
|||
<field name="first_refuse_date"
|
||||
attrs="{'invisible':[('state','!=','first_refusal')]}"/>
|
||||
<field name="is_excluded_suspension" groups="odex_benefit.group_benefit_manager,odex_benefit.group_benefit_branch_manager,odex_benefit.group_benefit_woman_commitee"/>
|
||||
<field name="sponsor_id" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
</group>
|
||||
<group>
|
||||
<!-- <field name="family_bank"-->
|
||||
<!-- attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>-->
|
||||
<field name="acc_number"/>
|
||||
<field name="account_holder"/>
|
||||
<field name="bank_id"/>
|
||||
<field name="acc_number" attrs="{'readonly':[('state','not in',['draft','complete_info'])]}"/>
|
||||
<field name="acc_holder_name" attrs="{'readonly':[('state','not in',['draft','complete_info'])]}"/>
|
||||
<field name="bank_id" attrs="{'readonly':[('state','not in',['draft','complete_info'])]}"/>
|
||||
<!-- <field name="iban" readonly="1" force_save="1"/>-->
|
||||
<field name="is_zakat_fitr" widget="boolean_toggle"
|
||||
attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
|
|
@ -527,16 +528,16 @@
|
|||
readonly="1"/>
|
||||
<field name="state_id" attrs="{'required':[('state','!=','draft')]}"
|
||||
readonly="1" string="Region"/>
|
||||
<field name="city_id" attrs="{'required':[('state','!=','draft')]}"
|
||||
<field name="city_id" attrs="{'required':[('state','!=','draft')],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"
|
||||
string="City"/>
|
||||
<field name="branch_id" required="1"/>
|
||||
<field name="branch_id" required="1" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="district_id"
|
||||
attrs="{'required':[('state','!=','draft')]}"/>
|
||||
<field name="zip" attrs="{'required':[('state','!=','draft')]}"/>
|
||||
<field name="block" attrs="{'required':[('state','!=','draft')]}"/>
|
||||
attrs="{'required':[('state','!=','draft')],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="zip" attrs="{'required':[('state','!=','draft')],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="block" attrs="{'required':[('state','!=','draft')],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="house_number"
|
||||
attrs="{'required':[('state','!=','draft')]}"/>
|
||||
<field name="street" attrs="{'required':[('state','!=','draft')]}"/>
|
||||
attrs="{'required':[('state','!=','draft')],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="street" attrs="{'required':[('state','!=','draft')],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="lat"
|
||||
attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="lon"
|
||||
|
|
@ -546,7 +547,7 @@
|
|||
<field name="floor"
|
||||
attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="housing_number"
|
||||
attrs="{'required':[('state','!=','draft')]}"/>
|
||||
attrs="{'required':[('state','!=','draft')],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="nearby_mosque"
|
||||
attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="housing_note"
|
||||
|
|
@ -577,7 +578,7 @@
|
|||
|
||||
<page string="Family Cars">
|
||||
<group>
|
||||
<field name="car_ids">
|
||||
<field name="car_ids" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}">
|
||||
<tree editable="bottom">
|
||||
<field name="benefit_id" invisible="1"/>
|
||||
<field name="name"/>
|
||||
|
|
@ -592,7 +593,7 @@
|
|||
</page>
|
||||
<page string="Family Loans">
|
||||
<group>
|
||||
<field name="family_debits_ids">
|
||||
<field name="family_debits_ids" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}">
|
||||
<form string="Family Loans">
|
||||
<sheet>
|
||||
<group>
|
||||
|
|
@ -648,7 +649,7 @@
|
|||
<!-- </field>-->
|
||||
<!-- </group>-->
|
||||
<group>
|
||||
<field name="expenses_ids">
|
||||
<field name="expenses_ids" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}">
|
||||
<tree editable="top">
|
||||
<field name="benefit_id" invisible="1"/>
|
||||
<field name="expenses_type" invisible="1"/>
|
||||
|
|
@ -661,7 +662,7 @@
|
|||
</page>
|
||||
<page string="Income and salary" attrs="{'invisible':[('state','=','draft')]}">
|
||||
<group string="Income and salary">
|
||||
<field name="salary_ids">
|
||||
<field name="salary_ids" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}">
|
||||
<tree editable="bottom">
|
||||
<field name="benefit_id" invisible="1"/>
|
||||
<field name="income_type"/>
|
||||
|
|
@ -724,46 +725,46 @@
|
|||
<!-- <field name="hospital_id"/>-->
|
||||
<!-- <field name="hospital_attach"/>-->
|
||||
<!-- <field name="is_smoke" widget="boolean_toggle"/>-->
|
||||
<field name="is_diseases"/>
|
||||
<field name="is_diseases" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<!--disability-->
|
||||
<field name="is_disability"/>
|
||||
<field name="is_insurance"/>
|
||||
<field name="is_disability" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="is_insurance" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<!--hospital-->
|
||||
<field name="hospital_id"/>
|
||||
<field name="hospital_card"/>
|
||||
<field name="hospital_id" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="hospital_card" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
</group>
|
||||
<!--Weight rate-->
|
||||
<group string="Weight">
|
||||
<field name="weight"/>
|
||||
<field name="height"/>
|
||||
<field name="weight" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="height" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="p_weight" force_save="1"/>
|
||||
</group>
|
||||
<group string="Diseases">
|
||||
<!-- !--diseases–>-->
|
||||
<field name="diseases_type"
|
||||
attrs="{'invisible': [('is_diseases', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_diseases', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="treatment_used"
|
||||
attrs="{'invisible': [('is_diseases', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_diseases', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="treatment_amount"
|
||||
attrs="{'invisible': [('is_diseases', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_diseases', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="is_treatment_amount_country"
|
||||
attrs="{'invisible': [('is_diseases', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_diseases', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="treatment_amount_country_Monthly"
|
||||
attrs="{'invisible': [('is_treatment_amount_country', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_treatment_amount_country', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="treatment_amount_country_description"
|
||||
attrs="{'invisible': [('is_treatment_amount_country', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_treatment_amount_country', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="treatment_amount_country_attach"
|
||||
attrs="{'invisible': [('is_treatment_amount_country', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_treatment_amount_country', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
</group>
|
||||
<group string="disability">
|
||||
<field name="disability_type"
|
||||
attrs="{'invisible': [('is_disability', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_disability', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="disability_accessories"
|
||||
attrs="{'invisible': [('is_disability', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_disability', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="disability_attach"
|
||||
attrs="{'invisible': [('is_disability', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_disability', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
<field name="disability_amount"
|
||||
attrs="{'invisible': [('is_disability', '=', False)]}"/>
|
||||
attrs="{'invisible': [('is_disability', '=', False)],'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
|
@ -805,7 +806,7 @@
|
|||
<field name="black_list_message"/>
|
||||
</page>
|
||||
<page string="Attachments">
|
||||
<field name="attachment_ids" widget="one2many_list">
|
||||
<field name="attachment_ids" widget="one2many_list" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}">
|
||||
<tree editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="datas"/>
|
||||
|
|
@ -869,6 +870,23 @@
|
|||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="grant_benefit_form_for_manager" model="ir.ui.view">
|
||||
<field name="name">grant.benefit.form</field>
|
||||
<field name="model">grant.benefit</field>
|
||||
<field name="inherit_id" ref="odex_benefit.grant_benefit_form"/>
|
||||
<field name="groups_id" eval="[(6,0,[ref('odex_benefit.group_benefit_manager')])]" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='acc_number']" position="replace">
|
||||
<field name="acc_number" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='acc_holder_name']" position="replace">
|
||||
<field name="acc_holder_name" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='bank_id']" position="replace">
|
||||
<field name="bank_id" attrs="{'readonly':[('state','not in',['draft','complete_info','edit_info'])]}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record id="grant_benefit_tree" model="ir.ui.view">
|
||||
<field name="name">grant.benefit.tree</field>
|
||||
<field name="model">grant.benefit</field>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
from datetime import date
|
||||
|
||||
from odoo import models, fields, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class ConfirmBenefitWizard(models.TransientModel):
|
||||
_name = 'confirm.benefit.wizard'
|
||||
_description = 'Confirm Benefit Wizard'
|
||||
|
||||
journal_id = fields.Many2one(comodel_name='account.journal', string="Journal", required=True)
|
||||
payment_method_id = fields.Many2one(comodel_name='account.payment.method', string='Payment Type', required=True)
|
||||
|
||||
name = fields.Char(string="Name", default=lambda self: "Family Expense -%s" % date.today())
|
||||
date = fields.Date(string="Date", default=fields.Date.context_today, required=True)
|
||||
|
||||
def action_confirm_selected(self):
|
||||
active_ids = self.env.context.get('default_benefit_ids', [])
|
||||
benefits = self.env['grant.benefit'].browse(active_ids)
|
||||
|
||||
if any(benefit.state not in ('second_approve', 'temporarily_suspend', 'suspend') for benefit in benefits):
|
||||
raise UserError(_("All selected benefits should be either state of "
|
||||
"'second_approve','temporarily_suspend','suspend' state."))
|
||||
|
||||
validation_setting = self.env["family.validation.setting"].search([], limit=1)
|
||||
|
||||
payment_method_line = self.env['account.payment.method.line'].search(
|
||||
[('payment_method_id', '=', self.payment_method_id.id)], limit=1)
|
||||
|
||||
if not validation_setting.cash_expense_account_id or not validation_setting.meal_expense_account_id or not validation_setting.clothing_expense_account_id:
|
||||
raise UserError(_("Please configure the expense accounts in the validation settings."))
|
||||
if not payment_method_line:
|
||||
raise UserError(_("Payment method is not configured for the selected journal."))
|
||||
|
||||
credit_account_id = payment_method_line.payment_account_id.id
|
||||
|
||||
if not credit_account_id:
|
||||
raise UserError(_("Payment method is not configured for the selected journal."))
|
||||
|
||||
if benefits:
|
||||
lines = []
|
||||
for benefit in benefits:
|
||||
lines += self._prepare_entry_lines(benefit, validation_setting, credit_account_id)
|
||||
|
||||
self.create_entry(self.journal_id.id, lines)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def _prepare_entry_lines(self, benefit, validation_setting, credit_account_id):
|
||||
"""Prepare debit and credit lines for a benefit"""
|
||||
entry_lines = []
|
||||
|
||||
expense_types = [
|
||||
('meal', 'family_monthly_meals', validation_setting.meal_expense_account_id.id),
|
||||
('cash', 'family_monthly_income', validation_setting.cash_expense_account_id.id),
|
||||
('clothing', 'family_monthly_clotting', validation_setting.clothing_expense_account_id.id),
|
||||
]
|
||||
|
||||
for expense_type, field, debit_account_id in expense_types:
|
||||
amount = getattr(benefit, field, 0.0)
|
||||
if benefit.district_id.meal_card and expense_type == 'meal':
|
||||
continue
|
||||
if amount:
|
||||
name = _("Family Expense - %s") % expense_type
|
||||
entry_lines.append(self._create_debit_line(benefit, debit_account_id, amount, name))
|
||||
entry_lines.append(self._create_credit_line(benefit, credit_account_id, amount, name))
|
||||
|
||||
return entry_lines
|
||||
|
||||
def _create_debit_line(self, benefit, account_id, amount, name):
|
||||
"""Create a debit line"""
|
||||
return (0, 0, {
|
||||
'name': name,
|
||||
'benefit_family_id': benefit.id,
|
||||
'partner_id': benefit.partner_id.id,
|
||||
'analytic_account_id': benefit.branch_id.analytic_account_id.id,
|
||||
'account_id': account_id,
|
||||
'debit': amount,
|
||||
'credit': 0.0,
|
||||
})
|
||||
|
||||
def _create_credit_line(self, benefit, account_id, amount, name):
|
||||
"""Create a credit line"""
|
||||
return (0, 0, {
|
||||
'name': name,
|
||||
'benefit_family_id': benefit.id,
|
||||
'partner_id': benefit.partner_id.id,
|
||||
'analytic_account_id': benefit.branch_id.analytic_account_id.id,
|
||||
'account_id': account_id,
|
||||
'debit': 0.0,
|
||||
'credit': amount,
|
||||
})
|
||||
|
||||
def create_entry(self, journal_id, lines):
|
||||
"""Create an account move entry"""
|
||||
move_vals = {
|
||||
'journal_id': journal_id,
|
||||
'date': self.date,
|
||||
'ref': self.name,
|
||||
'line_ids': lines,
|
||||
}
|
||||
self.env['account.move'].create(move_vals)
|
||||
return True
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
<record id="view_confirm_benefit_wizard_form" model="ir.ui.view">
|
||||
<field name="name">confirm.benefit.wizard.form</field>
|
||||
<field name="model">confirm.benefit.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Confirm Benefit">
|
||||
<group>
|
||||
<field name="journal_id" required="1"/>
|
||||
<field name="payment_method_id" required="1"/>
|
||||
<field name="name" readonly="1"/>
|
||||
<field name="date" required="1"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button string="Confirm" type="object" name="action_confirm_selected" class="oe_highlight"/>
|
||||
<button string="Cancel" class="btn-default" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue