[IMP] odex_benefit: IMP benefit

This commit is contained in:
younes 2025-10-28 16:06:53 +01:00
parent ec9d35b682
commit 19bcb2c21b
8 changed files with 79 additions and 31 deletions

View File

@ -402,6 +402,8 @@ class GrantBenefitProfile(models.Model):
('black_list', 'Black List'),
], string='state', default="draft", tracking=True, group_expand='_expand_states')
branch_custom_id = fields.Many2one('branch.settings', string="Branch")
branch_family_id = fields.Many2one('branch.settings', string="Family Branch")
branch_has_employees = fields.Boolean('Has Employees In branch',related="branch_family_id.has_employees")
district_id = fields.Many2one('res.districts', string="District", domain="[('branch_custom_id','=',branch_custom_id)]")
meal_card = fields.Boolean(string="Meal Card",related="district_id.meal_card", store=True,related_sudo=True)
attachment_ids = fields.One2many('ir.attachment', 'benefit_id')

View File

@ -727,6 +727,7 @@ class BranchSettings(models.Model):
('governorates', 'Governorates')],
string='Branch Type')
city_id = fields.Many2one('res.country.city')
has_employees = fields.Boolean('Has Employees' ,defualt=True)
class RelationSettings(models.Model):
_name = 'relation.settings'

View File

@ -9,6 +9,7 @@ class ConfirmBenefitExpense(models.Model):
_name = 'confirm.benefit.expense'
_description = 'Confirm Benefit Expense'
_inherit = ['mail.thread', 'mail.activity.mixin']
_order = "family_expense_seq desc"
# region [Default Methods]
@ -24,7 +25,7 @@ class ConfirmBenefitExpense(models.Model):
# endregion [Default Methods]
family_expense_seq = fields.Char(string="Family Expense Sequence", copy=False, readonly=True,
family_expense_seq = fields.Char(string="Number", copy=False, readonly=True,
default=lambda x: _('New'))
state = fields.Selection(selection=[
('draft', 'Draft'),
@ -38,7 +39,7 @@ class ConfirmBenefitExpense(models.Model):
expense_type = fields.Selection(selection=[
('family_expense', 'Family Expense'),
('family_invoice', 'Meal Card Invoice'),
], string='Expense Type', default='family_expense', required=True, states={'confirm': [('readonly', True)]})
], string='Expense Type', default='family_expense', required=True)
journal_id = fields.Many2one(comodel_name='account.journal', string="Journal", copy=False)
name = fields.Char(string="Name", states={'confirm': [('readonly', True)]}, copy=False)
@ -76,9 +77,12 @@ class ConfirmBenefitExpense(models.Model):
family_monthly_income = fields.Float(string="Total Monthly Income", compute='_get_family_monthly_values')
family_monthly_meals = fields.Float(string="Total Monthly Meals", compute='_get_family_monthly_values')
family_monthly_clotting = fields.Float(string="Total Monthly Clotting", compute='_get_family_monthly_values')
family_monthly_total = fields.Float(string="Total", compute='_get_family_monthly_values')
branch_custom_id = fields.Many2one(comodel_name='branch.settings', string="Branch")
family_domain_ids = fields.Many2many(comodel_name='grant.benefit', compute='_compute_domain_ids')
journal_domain_ids = fields.Many2many(comodel_name='account.journal', compute='_compute_domain_ids')
company_id = fields.Many2one('res.company', default=lambda self: self.env.company)
currency_id = fields.Many2one(comodel_name='res.currency',string="Company Currency",related='company_id.currency_id')
@api.model
def create(self, vals):
@ -107,6 +111,7 @@ class ConfirmBenefitExpense(models.Model):
self.ensure_one()
for line in self.benefit_expense_line_ids:
family = line.family_id
income,meals,clotting = 0,0,0
if not family:
continue
monthly_meals = family.family_monthly_meals
@ -121,10 +126,16 @@ class ConfirmBenefitExpense(models.Model):
'end_date': self.end_date,
}
if self.expense_type == 'family_expense':
if self.cash_expense:
income = family.family_monthly_income
if self.meal_expense:
meals = monthly_meals
if self.cloth_expense:
clotting = family.family_monthly_clotting
vals.update({
'family_monthly_income': family.family_monthly_income,
'family_monthly_meals': monthly_meals,
'family_monthly_clotting': family.family_monthly_clotting,
'family_monthly_income': income,
'family_monthly_meals': meals,
'family_monthly_clotting': clotting,
})
else:
vals.update({
@ -143,6 +154,10 @@ class ConfirmBenefitExpense(models.Model):
if not families:
raise UserError(_("Please select at least one family to calculate."))
if rec.expense_type == 'family_expense':
if not rec.cash_expense and not rec.meal_expense and not rec.cloth_expense:
raise UserError(_("At least one expense type should be selected."))
rec.benefit_expense_line_ids.unlink()
lines = []
for fam in families:
@ -224,6 +239,7 @@ class ConfirmBenefitExpense(models.Model):
rec.family_monthly_income = sum(rec.benefit_expense_line_ids.mapped('family_monthly_income'))
rec.family_monthly_meals = sum(rec.benefit_expense_line_ids.mapped('family_monthly_meals'))
rec.family_monthly_clotting = sum(rec.benefit_expense_line_ids.mapped('family_monthly_clotting'))
rec.family_monthly_total = rec.family_monthly_income + rec.family_monthly_meals + rec.family_monthly_clotting
@api.onchange('expense_type')
def _onchange_journal_id(self):
@ -267,13 +283,6 @@ class ConfirmBenefitExpense(models.Model):
self.benefit_expense_line_ids.unlink()
self.state = 'draft'
@api.constrains('expense_type', 'cash_expense', 'meal_expense', 'cloth_expense')
def _constraint_check_at_least_one_expense(self):
for rec in self:
if rec.expense_type == 'family_expense':
if not rec.cash_expense and not rec.meal_expense and not rec.cloth_expense:
raise UserError(_("At least one expense type should be selected."))
def _get_total_move_lines(self):
for rec in self:
rec.total_moves = self.env['account.move'].search_count([

View File

@ -980,6 +980,9 @@
<field name="branch"/>
<field name="branch_type"/>
</group>
<group>
<field name="has_employees"/>
</group>
</group>
</sheet>
</form>

View File

@ -311,6 +311,10 @@
readonly="1"
options="{'no_create': True, 'no_create_edit': True}"
groups="!odex_benefit.group_benefit_manager"/>
<field name="branch_family_id"
readonly="1"
options="{'no_create': True, 'no_create_edit': True}"/>
<field name="branch_has_employees"/>
<field name="district_id"
attrs="{'readonly':[('state', 'not in', ['draft', 'new', 'complete_info'])]}"
options="{'no_create': True, 'no_create_edit': True}"

View File

@ -7,10 +7,19 @@
<field name="arch" type="xml">
<tree>
<field name="family_expense_seq"/>
<field name="name" string="Process Details"/>
<field name="expense_type"/>
<field name="date"/>
<field name="state"/>
<field name="name" string="Description"/>
<field name="expense_type"/>
<field name="branch_custom_id"/>
<field name="currency_id" invisible="1" groups="base.group_multi_currency"/>
<field name="family_monthly_total" decoration-bf="1" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="state" widget="badge"
decoration-info="state in ['draft','calculated']"
decoration-warning="state in ['account_manager','depart_manager','assistant_general_manager']"
decoration-success="state in ['confirm']"
decoration-muted="state == 'cancel'"
/>
</tree>
</field>
</record>
@ -64,15 +73,14 @@
</div>
<group>
<group>
<field name="name" required="1" string="Process Details"
<field name="name" required="1" string="Description"
attrs="{'readonly':[('state', '!=', 'draft')]}"/>
<label for="start_date"/>
<div>
<label for="start_date" string="Period"/>
<div class="o_row">
<field name="start_date"
attrs="{'readonly':[('state', '!=', 'draft')]}"/>
<strong>
<label for="end_date"/>
</strong>
<i class="fa fa-long-arrow-right mx-2 oe_edit_only"
aria-label="Arrow icon" title="Arrow"/>
<field name="end_date"
attrs="{'readonly':[('state', '!=', 'draft')]}"/>
</div>
@ -81,7 +89,7 @@
<!-- <field name="payment_method_id" attrs="{'invisible': [('expense_type', '=', 'family_invoice')],'required': [('expense_type', '=', 'family_expense')]}"/>-->
</group>
<group>
<field name="expense_type" required="1"/>
<field name="expense_type" required="1" attrs="{'readonly':[('state', '!=', 'draft')]}"/>
<field name="journal_id" domain="[('id', 'in', journal_domain_ids)]"
attrs="{'required': [('expense_type', '=', 'family_invoice')],'invisible': [('expense_type', '!=', 'family_invoice')]}"
forec_save="1"/>
@ -99,14 +107,22 @@
attrs="{'invisible': [('expense_type', '=', 'family_invoice')], 'readonly':[('state', '!=', 'draft')]}"/>
<field name="cloth_expense"
attrs="{'invisible': [('expense_type', '=', 'family_invoice')], 'readonly':[('state', '!=', 'draft')]}"/>
<field name="company_id" groups="base.group_multi_company"/>
</group>
<group>
<field name="family_monthly_income"
<field name="currency_id" invisible="1" groups="base.group_multi_currency"/>
<field name="family_monthly_income" widget="monetary"
options="{'currency_field': 'currency_id'}"
attrs="{'invisible': ['|',('expense_type', '=', 'family_invoice'),('cash_expense', '=', False)]}"/>
<field name="family_monthly_meals"
<field name="family_monthly_meals" widget="monetary"
options="{'currency_field': 'currency_id'}"
attrs="{'invisible': [('expense_type', '=', 'family_expense'),('meal_expense', '=', False)]}"/>
<field name="family_monthly_clotting"
<field name="family_monthly_clotting" widget="monetary"
options="{'currency_field': 'currency_id'}"
attrs="{'invisible': ['|',('expense_type', '=', 'family_invoice'),('cloth_expense', '=', False)]}"/>
<field name="family_monthly_total" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
</group>
</group>
<!-- Notebook with Families page -->
@ -121,9 +137,12 @@
<field name="end_date" invisible="1"/>
<field name="meal_card"/>
<field name="benefit_member_count"/>
<field name="family_monthly_income" attrs="{'column_invisible': [('parent.cash_expense', '!=', True)]}"/>
<field name="family_monthly_meals" attrs="{'column_invisible': [('parent.meal_expense', '!=', True)]}"/>
<field name="family_monthly_clotting" attrs="{'column_invisible': [('parent.cloth_expense', '!=', True)]}"/>
<field name="family_monthly_income"
attrs="{'column_invisible': [('parent.cash_expense', '!=', True)]}"/>
<field name="family_monthly_meals"
attrs="{'column_invisible': [('parent.meal_expense', '!=', True)]}"/>
<field name="family_monthly_clotting"
attrs="{'column_invisible': [('parent.cloth_expense', '!=', True)]}"/>
<field name="total_family_expenses"/>
</tree>
</field>

View File

@ -40,6 +40,13 @@ class ReasearcherFamilyWizard(models.TransientModel):
def _default_benefit(self):
return self._context.get('active_id')
def _default_branch_custom_id(self):
benefit_id = self._context.get('active_id')
if benefit_id:
benefit = self.env['grant.benefit'].browse(benefit_id)
return benefit.branch_family_id.id
return False
# selector = fields.Selection([
# ('researcher', 'Researcher'),
# ('researcher_team', 'Researcher Team'),
@ -48,7 +55,8 @@ class ReasearcherFamilyWizard(models.TransientModel):
researcher_team = fields.Many2one("committees.line", string="Researcher Team",
domain="[('branch_custom_id', '=',branch_custom_id)]")
benefit_id = fields.Many2one("grant.benefit", string="Benefit", default=_default_benefit)
branch_custom_id = fields.Many2one("branch.settings", string="Department", related="benefit_id.branch_custom_id")
branch_custom_id = fields.Many2one("branch.settings", string="Department", default=_default_branch_custom_id)
branch_has_employees = fields.Boolean('Has Employees In branch',related="benefit_id.branch_has_employees")
is_submitted = fields.Boolean(string="Submitted", default=False)
def submit_family(self):
@ -56,7 +64,8 @@ class ReasearcherFamilyWizard(models.TransientModel):
rec.benefit_id.with_context(bypass_attachments_requirement=True).write({
'state': 'complete_info',
'contact_type': 'sms',
'researcher_id': rec.researcher_team.id
'researcher_id': rec.researcher_team.id,
'branch_custom_id':rec.branch_custom_id.id,
})
visit_record = self.env['visit.location'].create({
'benefit_id': rec.benefit_id.id,

View File

@ -32,7 +32,8 @@
<group>
<field name="benefit_id" invisible="1"/>
<field name="is_submitted" invisible="1"/>
<field name="branch_custom_id" invisible="1"/>
<field name="branch_custom_id" attrs="{'invisible':[('branch_has_employees','=',True)]}"/>
<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}"/>
</group>
<footer>