From 56038744e5ded962d3e86c2230357574c79e5c50 Mon Sep 17 00:00:00 2001 From: blackbelts <74664702+eslamtalaat74@users.noreply.github.com> Date: Tue, 16 Sep 2025 12:42:16 +0300 Subject: [PATCH] activity modifications 3 --- .../odex25_program_activity/models/program.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/odex25_ensan/odex25_program_activity/models/program.py b/odex25_ensan/odex25_program_activity/models/program.py index 855d3f5a7..252402bf3 100644 --- a/odex25_ensan/odex25_program_activity/models/program.py +++ b/odex25_ensan/odex25_program_activity/models/program.py @@ -178,6 +178,19 @@ class PaProgram(models.Model): active = fields.Boolean(string='Program Status', default=True) + # @api.constrains('name') + # def _create_program_account(self): + # for rec in self: + # if not rec.name: + # continue + # # check if analytic account already exists + # analytic = self.env["account.analytic.account"].search([("name", "=", rec.name)], limit=1) + # if not analytic: + # self.env["account.analytic.account"].create({ + # "name": rec.name, + # }) + + @api.constrains('payment_type', 'sponsor_id') def _check_sponsor_if_paid(self): for record in self: @@ -224,6 +237,28 @@ class PaProgramActivity(models.Model): estimated_budget = fields.Float("Estimated Budget") active = fields.Boolean("Active", default=True) + @api.model + def create(self, vals): + res = super().create(vals) # ✅ fix + if not res.analytic_account_id: + account = self.env['account.analytic.account'].create({ + 'name': res.name, + 'active': True, + }) + res.analytic_account_id = account.id + return res + + def write(self, vals): + res = super().write(vals) # ✅ same correction here + for record in self: + if not record.analytic_account_id: + account = self.env['account.analytic.account'].create({ + 'name': record.name, + 'active': True, + }) + record.analytic_account_id = account.id + return res + class PaProgramMedad(models.Model): _name = 'pa.program.medad' @@ -243,6 +278,28 @@ class PaProgramMedad(models.Model): estimated_budget = fields.Float("Estimated Budget") active = fields.Boolean("Active", default=True) + @api.model + def create(self, vals): + res = super().create(vals) # ✅ fix + if not res.analytic_account_id: + account = self.env['account.analytic.account'].create({ + 'name': res.name, + 'active': True, + }) + res.analytic_account_id = account.id + return res + + def write(self, vals): + res = super().write(vals) # ✅ same correction here + for record in self: + if not record.analytic_account_id: + account = self.env['account.analytic.account'].create({ + 'name': record.name, + 'active': True, + }) + record.analytic_account_id = account.id + return res + # Example family/beneficiary for demo: you should replace with your actual model