From 634129d747db170e3563ef2b862acefae585851e Mon Sep 17 00:00:00 2001 From: Mazen Abdo Date: Sun, 15 Sep 2024 11:02:40 +0300 Subject: [PATCH] fix button check budget --- .../exp_budget_check/models/hr_expense.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/odex25_accounting/exp_budget_check/models/hr_expense.py b/odex25_accounting/exp_budget_check/models/hr_expense.py index f88e4e790..a8a73878b 100644 --- a/odex25_accounting/exp_budget_check/models/hr_expense.py +++ b/odex25_accounting/exp_budget_check/models/hr_expense.py @@ -39,6 +39,12 @@ class BudgetConfirmationCustom(models.Model): class AccountMove(models.Model): _inherit = 'hr.expense' + partner_id = fields.Many2one( + 'res.partner', string='Vendor', readonly=True, + states={"draft": [("readonly", False)]} + ) + address_id = fields.Many2one( + 'res.partner', related='employee_id.user_id.partner_id') state = fields.Selection(selection_add=[ ('confirm', 'Confirm'), ('wait_budget', 'Wait Budget'), @@ -135,20 +141,21 @@ class AccountMove(models.Model): def action_budget(self): budget_lines = self.analytic_account_id.crossovered_budget_line.filtered( - lambda x: x.crossovered_budget_id.state == 'done' and fields.Date.from_string( - x.date_from) <= fields.Date.from_string(self.date) <= fields.Date.from_string(x.date_to)) + lambda x: x.crossovered_budget_id.state == 'done' and + fields.Date.from_string(x.date_from) <= fields.Date.from_string(self.date) <= fields.Date.from_string(x.date_to) + ) if not budget_lines: - raise UserError( - _('analytic account is %s not link with budget') % self.analytic_account_id.name) + raise UserError(_('Analytic account %s is not linked with budget') % self.analytic_account_id.name) else: - remain = abs(budget_lines[0].remain) + budget_line = budget_lines[0] + remain = abs(budget_line.remain) amount = self.total_amount new_remain = remain - amount data = { - 'name': _('Expense :%s') % self.employee_id.name, + 'name': _('Expense: %s') % self.employee_id.name, 'date': self.date, - 'beneficiary_id': self.employee_id.user_id.partner_id, + 'beneficiary_id': self.employee_id.user_id.partner_id.id, # Ensure correct ID is used 'type': 'expense', 'ref': self.name, 'description': self.name, @@ -157,7 +164,7 @@ class AccountMove(models.Model): 'amount': amount, 'analytic_account_id': self.analytic_account_id.id, 'description': self.product_id.name, - 'budget_line_id': budget_lines[0].id, + 'budget_line_id': budget_line.id, 'remain': new_remain + amount, 'new_balance': new_remain, 'account_id': self.account_id.id