[IMP] odex_benefit: IMP benefit

This commit is contained in:
younes 2025-12-09 13:42:40 +01:00
parent b14bc65e45
commit 4f95de969d
7 changed files with 182 additions and 39 deletions

View File

@ -30,6 +30,7 @@ class ConfirmBenefitExpense(models.Model):
default=lambda x: _('New')) default=lambda x: _('New'))
state = fields.Selection(selection=[ state = fields.Selection(selection=[
('draft', 'Draft'), ('draft', 'Draft'),
('waiting_processing', 'Waiting for Processing'),
('calculated', 'Calculated'), ('calculated', 'Calculated'),
('assistant_general_manager', 'Waiting For The Assistant General Manager'), ('assistant_general_manager', 'Waiting For The Assistant General Manager'),
('accounting_approve', 'Accounting Approve'), ('accounting_approve', 'Accounting Approve'),
@ -55,7 +56,7 @@ class ConfirmBenefitExpense(models.Model):
cloth_expense = fields.Boolean(string='Include Clothing Expense', default=True, cloth_expense = fields.Boolean(string='Include Clothing Expense', default=True,
states={'confirm': [('readonly', True)]}) states={'confirm': [('readonly', True)]})
payment_order_id = fields.Many2one('payment.orders', string='Payment Order', ondelete="set null", copy=False) payment_order_id = fields.Many2one('payment.orders', string='Payment Order', ondelete="set null", copy=False)
move_id = fields.Many2one('account.move', ondelete='cascade') move_id = fields.Many2one('account.move')
available_payment_method_line_ids = fields.Many2many(comodel_name='account.payment.method.line') available_payment_method_line_ids = fields.Many2many(comodel_name='account.payment.method.line')
family_monthly_income = fields.Float(string="Total Monthly Income", compute='_get_family_monthly_values', family_monthly_income = fields.Float(string="Total Monthly Income", compute='_get_family_monthly_values',
store=True) store=True)
@ -98,6 +99,7 @@ class ConfirmBenefitExpense(models.Model):
line_domain_ids = fields.Many2many(comodel_name='benefit.expense.line', compute='_compute_domain_ids', line_domain_ids = fields.Many2many(comodel_name='benefit.expense.line', compute='_compute_domain_ids',
string="Return Line Domain", string="Return Line Domain",
) )
assigned_supervisor_id = fields.Many2one('hr.employee',string='Assigned Supervisor',tracking=True,copy=False)
@api.depends('payment_order_id', 'payment_order_id.state', 'move_id', 'move_id.state') @api.depends('payment_order_id', 'payment_order_id.state', 'move_id', 'move_id.state')
def _compute_payment_move_state(self): def _compute_payment_move_state(self):
@ -321,7 +323,8 @@ class ConfirmBenefitExpense(models.Model):
self.state = 'assistant_general_manager' self.state = 'assistant_general_manager'
def action_accounting_approve(self): def action_accounting_approve(self):
self.state = 'accounting_approve' self.sudo().action_accounting_transfer()
self.sudo().state = 'accounting_approve'
def action_cancel(self): def action_cancel(self):
self.state = 'cancel' self.state = 'cancel'
@ -332,6 +335,39 @@ class ConfirmBenefitExpense(models.Model):
self.benefit_expense_line_ids.unlink() self.benefit_expense_line_ids.unlink()
self.state = 'draft' self.state = 'draft'
def action_reset_to_calculated(self):
self.ensure_one()
return {
'name': _('Reason for Return'),
'type': 'ir.actions.act_window',
'res_model': 'reason.for.return.wizard',
'view_mode': 'form',
'target': 'new',
}
def action_assign_supervisor(self):
self.ensure_one()
return {
'name': _('Assign to Supervisor'),
'type': 'ir.actions.act_window',
'res_model': 'assign.supervisor.wizard',
'view_mode': 'form',
'target': 'new',
}
def action_process_return(self):
self.ensure_one()
if self.state != 'waiting_processing':
raise UserError(_("You can only process when status is 'Waiting for Processing'."))
self.message_post(
body=_('<b>Processing Completed</b><br/><b>Processed By:</b> %s') % self.env.user.name,
subject=_('Return Processing Completed'),
message_type='notification',
)
self.state = 'calculated'
def action_open_related_move_records(self): def action_open_related_move_records(self):
moves = self.move_id.ids moves = self.move_id.ids
return { return {
@ -392,29 +428,30 @@ class ConfirmBenefitExpense(models.Model):
# Create Vendor Bill for Meal Card Invoice(othaime) # Create Vendor Bill for Meal Card Invoice(othaime)
account_id = validation_setting.meal_expense_account_id account_id = validation_setting.meal_expense_account_id
invoice_lines = [] invoice_lines = []
for line in lines.filtered(lambda l: l.meal_card): if lines.filtered(lambda l: l.meal_card):
family = line.family_id for line in lines.filtered(lambda l: l.meal_card):
invoice_lines.append((0, 0, { family = line.family_id
'name': f'{family.name}/{family.code}', invoice_lines.append((0, 0, {
'account_id': account_id.id, 'name': f'{family.name}/{family.code}',
'quantity': 1, 'account_id': account_id.id,
'benefit_family_id': family.id, 'quantity': 1,
'price_unit': line.family_monthly_othaime, 'benefit_family_id': family.id,
'price_unit': line.family_monthly_othaime,
'family_confirm_id': rec.id,
'analytic_account_id': family.branch_family_id.branch.analytic_account_id.id
}))
invoice_vals = {
'move_type': 'in_invoice',
'partner_id': validation_setting.meal_partner_id.id,
'invoice_date': rec.date,
'family_confirm_id': rec.id, 'family_confirm_id': rec.id,
'analytic_account_id': family.branch_family_id.branch.analytic_account_id.id 'benefit_family_ids': [(6, 0, rec.benefit_expense_line_ids.mapped('family_id').ids)],
})) 'journal_id': validation_setting.journal_id.id,
invoice_vals = { 'invoice_line_ids': invoice_lines,
'move_type': 'in_invoice', 'ref': rec.name,
'partner_id': validation_setting.meal_partner_id.id, }
'invoice_date': rec.date,
'family_confirm_id': rec.id,
'benefit_family_ids': [(6, 0, rec.benefit_expense_line_ids.mapped('family_id').ids)],
'journal_id': validation_setting.journal_id.id,
'invoice_line_ids': invoice_lines,
'ref': rec.name,
}
invoice = self.env['account.move'].create(invoice_vals) invoice = self.env['account.move'].create(invoice_vals)
rec.move_id = invoice rec.move_id = invoice
return True return True

View File

@ -171,4 +171,5 @@ access_expense_line_benefit_manager,access_expense_line_benefit_manager,model_be
access_expense_researcher,access_expense_researcher,model_benefit_expense_line,odex_benefit.group_benefit_info,1,0,0,0 access_expense_researcher,access_expense_researcher,model_benefit_expense_line,odex_benefit.group_benefit_info,1,0,0,0
access_family_bank_report_wizard,access_family_bank_report_wizard,model_family_bank_report_wizard,base.group_user,1,1,1,1 access_family_bank_report_wizard,access_family_bank_report_wizard,model_family_bank_report_wizard,base.group_user,1,1,1,1
access_return_reason,access_return_reason,model_return_reason,base.group_user,1,1,1,1 access_return_reason,access_return_reason,model_return_reason,base.group_user,1,1,1,1
access_return_reason_wizard,access_return_reason_wizard,model_return_reason_wizard,base.group_user,1,1,1,1 access_return_reason_wizard,access_return_reason_wizard,model_return_reason_wizard,base.group_user,1,1,1,1
access_assign_supervisor_wizard,access_assign_supervisor_wizard,model_assign_supervisor_wizard,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
171 access_expense_researcher access_expense_researcher model_benefit_expense_line odex_benefit.group_benefit_info 1 0 0 0
172 access_family_bank_report_wizard access_family_bank_report_wizard model_family_bank_report_wizard base.group_user 1 1 1 1
173 access_return_reason access_return_reason model_return_reason base.group_user 1 1 1 1
174 access_return_reason_wizard access_return_reason_wizard model_return_reason_wizard base.group_user 1 1 1 1
175 access_assign_supervisor_wizard access_assign_supervisor_wizard model_assign_supervisor_wizard base.group_user 1 1 1 1

View File

@ -1066,6 +1066,8 @@
parent="education_main_menu" action="education_exam_type_action" sequence="9"/> parent="education_main_menu" action="education_exam_type_action" sequence="9"/>
<menuitem id="menu_confirm_benefit_expense" name="Benefit Expense Flow" parent="odex_benefit.benefit_services" <menuitem id="menu_confirm_benefit_expense" name="Benefit Expense Flow" parent="odex_benefit.benefit_services"
action="action_confirm_benefit_expense" sequence="11" groups="odex_benefit.group_family_services_manager,odex_benefit.group_benefit_manager"/> action="action_confirm_benefit_expense" sequence="11" groups="odex_benefit.group_family_services_manager,odex_benefit.group_benefit_manager"/>
<menuitem id="menu_bank_return_benefit_expense" name="Bank Return Processing" parent="odex_benefit.benefit_services"
action="action_bank_return_benefit_expense" sequence="15" groups="odex_benefit.group_family_services_manager,odex_benefit.group_benefit_manager"/>
<menuitem id="menu_family_bank_report_root" <menuitem id="menu_family_bank_report_root"
name="Family Bank Report" name="Family Bank Report"
parent="account.menu_finance_payables" parent="account.menu_finance_payables"

View File

@ -49,6 +49,19 @@
groups="odex_benefit.group_family_services_manager" groups="odex_benefit.group_family_services_manager"
type="object" states="draft" class="btn btn-info"/> type="object" states="draft" class="btn btn-info"/>
<button name="action_assign_supervisor" string="Assign to Supervisor"
groups="odex_benefit.group_family_services_manager"
type="object"
attrs="{'invisible': ['|', ('state', '!=', 'draft'), ('is_return_calculation', '=', False)]}"
class="btn-primary"/>
<!-- Waiting Processing State Buttons -->
<button name="action_process_return" string="Process"
groups="odex_benefit.group_family_services_manager"
type="object"
states="waiting_processing"
class="oe_highlight"/>
<button string="Confirm" type="object" name="action_assistant_manager" class="oe_highlight" <button string="Confirm" type="object" name="action_assistant_manager" class="oe_highlight"
states="calculated" groups="odex_benefit.group_family_services_manager"/> states="calculated" groups="odex_benefit.group_family_services_manager"/>
<button string="Withdraw" type="object" name="action_reset_to_draft" class="btn btn-danger" <button string="Withdraw" type="object" name="action_reset_to_draft" class="btn btn-danger"
@ -59,15 +72,15 @@
<button string="Confirm" type="object" name="action_accounting_approve" class="oe_highlight" <button string="Confirm" type="object" name="action_accounting_approve" class="oe_highlight"
states="assistant_general_manager" states="assistant_general_manager"
groups="odex_benefit.group_benefit_manager"/> groups="odex_benefit.group_benefit_manager"/>
<button string="Reset" type="object" name="action_reset_to_draft" class="btn btn-danger" <button string="Reset" type="object" name="action_reset_to_calculated" class="btn btn-danger"
states="assistant_general_manager" states="assistant_general_manager"
groups="odex_benefit.group_benefit_manager"/> groups="odex_benefit.group_benefit_manager"/>
<button string="Accounting Transfer" type="object" name="action_accounting_transfer" <!--<button string="Accounting Transfer" type="object" name="action_accounting_transfer"
class="oe_highlight" groups="odex_benefit.group_family_services_manager" class="oe_highlight" groups="odex_benefit.group_family_services_manager"
attrs="{'invisible': ['|','|',('state', '!=', 'accounting_approve'),('payment_order_id','!=',False),('move_id','!=',False)]}" attrs="{'invisible': ['|','|',('state', '!=', 'accounting_approve'),('payment_order_id','!=',False),('move_id','!=',False)]}"
/> />-->
<button string="Reset" type="object" name="action_reset_to_draft" class="btn btn-danger" <button string="Reset" type="object" name="action_reset_to_calculated" class="btn btn-danger"
states="accounting_approve" groups="odex_benefit.group_family_services_manager"/> states="accounting_approve" groups="odex_benefit.group_family_services_manager"/>
</header> </header>
<sheet> <sheet>
@ -124,6 +137,9 @@
</div> </div>
<field name="is_return_calculation" widget="boolean_toggle" <field name="is_return_calculation" widget="boolean_toggle"
attrs="{'readonly':[('state', '!=', 'draft')]}"/> attrs="{'readonly':[('state', '!=', 'draft')]}"/>
<field name="assigned_supervisor_id"
attrs="{'invisible': ['|',('assigned_supervisor_id','=',False),('is_return_calculation', '=', False)]}"
readonly="1"/>
<field name="branch_custom_ids" required="1" <field name="branch_custom_ids" required="1"
widget="many2many_tags" attrs="{'readonly':[('state', '!=', 'draft')]}" widget="many2many_tags" attrs="{'readonly':[('state', '!=', 'draft')]}"
/> />
@ -146,7 +162,8 @@
</group> </group>
<!-- Notebook with Families page --> <!-- Notebook with Families page -->
<notebook> <notebook>
<page string="Family Monthly Expense" attrs="{'invisible': [('state', '=', 'draft')]}"> <page string="Family Monthly Expense"
attrs="{'invisible': [('state', 'in', ['draft','waiting_processing'])]}">
<div class="row mb-2"> <div class="row mb-2">
<!-- Family Count (Monthly Expense) --> <!-- Family Count (Monthly Expense) -->
<div class="col-6"> <div class="col-6">
@ -414,6 +431,14 @@
<field name="view_id" ref="view_confirm_benefit_expense_tree"/> <field name="view_id" ref="view_confirm_benefit_expense_tree"/>
</record> </record>
<record id="action_bank_return_benefit_expense" model="ir.actions.act_window">
<field name="name">Bank Return Processing</field>
<field name="res_model">confirm.benefit.expense</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('state','=','waiting_processing')]</field>
<field name="view_id" ref="view_confirm_benefit_expense_tree"/>
</record>
<record id="view_move_line_tree_new_code" model="ir.ui.view"> <record id="view_move_line_tree_new_code" model="ir.ui.view">
<field name="name">account.move.line.form</field> <field name="name">account.move.line.form</field>

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from odoo import models, fields, api from odoo import models, fields, api,_
class ReasonForReturnWizard(models.TransientModel): class ReasonForReturnWizard(models.TransientModel):
_name = 'reason.for.return.wizard' _name = 'reason.for.return.wizard'
@ -9,11 +9,33 @@ class ReasonForReturnWizard(models.TransientModel):
reason = fields.Text(string="reason for return", required=True) reason = fields.Text(string="reason for return", required=True)
def action_confirm(self): def action_confirm(self):
for record in self: active_id = self._context.get('active_id')
record.env['service.request'].browse(self._context.get('active_id')).write({ active_model = self._context.get('active_model')
'return_reason': record.reason,
if active_model == 'service.request':
self.env[active_model].browse(active_id).write({
'return_reason': self.reason,
'state': 'researcher', 'state': 'researcher',
}) })
elif active_model == 'confirm.benefit.expense':
expense = self.env[active_model].browse(active_id)
message = _(
'<b>State Changed:</b> %s → Calculated<br/>'
'<b>Reset By:</b> %s<br/>'
'<b>Reason:</b> %s'
) % (dict(expense._fields['state'].selection).get(expense.state), self.env.user.name,self.reason)
expense.sudo().message_post(
body=message,
subject=_('Benefit Expense Reset'),
message_type='notification',)
if expense.payment_order_id:
expense.sudo().payment_order_id.unlink()
if expense.move_id:
expense.sudo().move_id.unlink()
expense.sudo().state = 'calculated'
return {'type': 'ir.actions.act_window_close'}
class ReturnReasonWizard(models.TransientModel): class ReturnReasonWizard(models.TransientModel):
_name = "return.reason.wizard" _name = "return.reason.wizard"

View File

@ -192,3 +192,36 @@ class ReasearcherFamilyWizard(models.TransientModel):
subtype_id=self.env.ref('mail.mt_note').id, subtype_id=self.env.ref('mail.mt_note').id,
notify_by_email=False, notify_by_email=False,
) )
class AssignSupervisorWizard(models.TransientModel):
_name = 'assign.supervisor.wizard'
_description = 'Assign Supervisor Wizard'
supervisor_id = fields.Many2one('hr.employee',string='Supervisor',required=True,domain=[('job_id', '!=', False)])
def action_confirm(self):
self.ensure_one()
active_id = self._context.get('active_id')
active_model = self._context.get('active_model')
if active_model == 'confirm.benefit.expense':
expense = self.env[active_model].browse(active_id)
message = _(
'<b>Assigned to Supervisor</b><br/>'
'<b>Supervisor:</b> %s<br/>'
'<b>Assigned By:</b> %s'
) % (self.supervisor_id.name,self.env.user.name)
expense.message_post(
body=message,
subject=_('Assigned to Supervisor'),
message_type='notification',
)
expense.write({
'assigned_supervisor_id': self.supervisor_id.id,
'state': 'waiting_processing'
})
return {'type': 'ir.actions.act_window_close'}

View File

@ -8,13 +8,14 @@
<form> <form>
<sheet> <sheet>
<group> <group>
<!-- <field name="selector"/>--> <!-- <field name="selector"/>-->
<field name="member_id"/> <field name="member_id"/>
<!-- <field name="researcher_id" attrs="{'invisible':[('selector','=','researcher_team')]}"/>--> <!-- <field name="researcher_id" attrs="{'invisible':[('selector','=','researcher_team')]}"/>-->
<field name="researcher_team"/> <field name="researcher_team"/>
</group> </group>
<footer> <footer>
<button name="submit_member" type="object" string="Submit" class="oe_highlight" attrs="{'invisible':[('member_id','=',False)]}"/> <button name="submit_member" type="object" string="Submit" class="oe_highlight"
attrs="{'invisible':[('member_id','=',False)]}"/>
or or
<button special="cancel" string="Cancel"/> <button special="cancel" string="Cancel"/>
</footer> </footer>
@ -34,10 +35,12 @@
<field name="is_submitted" invisible="1"/> <field name="is_submitted" invisible="1"/>
<field name="branch_custom_id" attrs="{'invisible':[('branch_has_employees','=',True)]}"/> <field name="branch_custom_id" attrs="{'invisible':[('branch_has_employees','=',True)]}"/>
<field name="branch_has_employees" invisible="1"/> <field name="branch_has_employees" invisible="1"/>
<field name="researcher_team" required="1" options="{'no_create': True, 'no_create_edit': True,'no_quick_create': True, 'no_open': True}"/> <field name="researcher_team" required="1"
options="{'no_create': True, 'no_create_edit': True,'no_quick_create': True, 'no_open': True}"/>
</group> </group>
<footer> <footer>
<button name="submit_family" type="object" string="Submit" class="oe_highlight" attrs="{'invisible':['|',('benefit_id','=',False),('is_submitted','=',True)]}"/> <button name="submit_family" type="object" string="Submit" class="oe_highlight"
attrs="{'invisible':['|',('benefit_id','=',False),('is_submitted','=',True)]}"/>
<button special="cancel" string="Return to Record" class="btn-secondary"/> <button special="cancel" string="Return to Record" class="btn-secondary"/>
</footer> </footer>
</sheet> </sheet>
@ -45,5 +48,25 @@
</field> </field>
</record> </record>
<record id="view_assign_supervisor_wizard_form" model="ir.ui.view">
<field name="name">assign.supervisor.wizard.form</field>
<field name="model">assign.supervisor.wizard</field>
<field name="arch" type="xml">
<form string="Assign to Supervisor">
<group>
<field name="supervisor_id"
placeholder="Select a supervisor..."
required="1"
options="{'no_create': True, 'no_create_edit': True}"/>
</group>
<footer>
<button string="Confirm Assignment" name="action_confirm"
type="object" class="btn-primary"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
</data> </data>
</odoo> </odoo>