Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
2.0 kB
2
Indexable
Never
@api.depends('project_id','ticket_amt_account')
    def get_budget_amt(self):
        for record in self:
            budget_amt = 0.00
            actual_amt = 0.00
            if record.project_id and record.ticket_amt_account in ['conserve','client']:
                
                amount_budget = sum(record.project_id.sale_order_id.travel_line_ids.mapped('amount_in_currency'))
                budget_amt = amount_budget
                
                if record.ticket_amt_account == 'conserve':
                    conserve_exp_id =self.env['travel.expense.statement'].search([('project_name','=',record.project_id.id)])
                    actual_amt = sum(conserve_exp_id.convey_ids.mapped('total_amount'))
                else:
                    clent_exp_id =self.env['travel.expenses'].search([('project_name','=',record.project_id.id)])
                    actual_amt = sum(clent_exp_id.convey_ids.mapped('total_amount'))
                
                
            elif record.ticket_amt_account == 'conserve_exp':
                account_id = self.env['account.account'].search([('name','=','Travel Expenses - Client Expenses Conserve Account')])
                
                budget = self.env['account.analytic.crossovered.budget'].search([('date_from','<=',record.meeting_date),
                                                                        ('date_to','>=',record.meeting_date)
                                                                        ])
                if account_id:
                    budget_ids = budget.crossovered_budget_line.filtered(lambda x: x.analytic_account_id.id == account_id.id)
                    if budget_ids:
                        budget_amt = sum(budget_amt.mapped('planned_amount'))
                        actual_amt = sum(budget_amt.mapped('practical_amount'))
                        
            record.budget_amt = budget_amt
            record.actual_amt = actual_amt
            record.travel_balance_amt = budget_amt - actual_amt
    
Leave a Comment