fix button check budget

This commit is contained in:
Mazen Abdo 2024-09-15 11:02:40 +03:00
parent d2ce28bf95
commit 634129d747
1 changed files with 15 additions and 8 deletions

View File

@ -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