diff --git a/odex25_accounting/account_budget_custom/models/account_budget.py b/odex25_accounting/account_budget_custom/models/account_budget.py index 89b75986e..b4523e072 100644 --- a/odex25_accounting/account_budget_custom/models/account_budget.py +++ b/odex25_accounting/account_budget_custom/models/account_budget.py @@ -78,17 +78,26 @@ class CrossoveredBudgetLines(models.Model): confirm = fields.Float(string='Confirm Amount', compute='_compute_confirm', help=_('Total amount of confirmed purchase orders')) - @api.depends('analytic_account_id') def _compute_confirm(self): for rec in self: orders = self.env['purchase.order.line'].search( [('account_analytic_id', '=', rec.analytic_account_id.id), - ('order_id.state', 'in', ['purchase','done'])]).mapped('order_id') - total_orders = sum(orders.mapped('amount_total')) + ('order_id.state', 'in', ['purchase', 'done'])]).mapped('order_id') + orders_without_tax = sum(orders.mapped('amount_total')) - sum(orders.mapped('amount_tax')) + need_tax = 0 + for line in orders.mapped('order_line'): + vals = line._prepare_compute_all_values() + taxes = line.taxes_id.filtered(lambda x: x.analytic).compute_all( + vals['price_unit'], + vals['currency_id'], + vals['product_qty'], + vals['product'], + vals['partner']) + need_tax += sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])) invoiced = self.env['account.move'].search( [('purchase_id', 'in', orders.ids), ('state', 'not in', ['draft', 'cancel'])]).mapped('amount_total') - rec.confirm = (total_orders - sum(invoiced)) * -1 + rec.confirm = ((orders_without_tax + need_tax) - sum(invoiced)) * -1 @api.depends('analytic_account_id') def _compute_reserve(self): @@ -96,24 +105,18 @@ class CrossoveredBudgetLines(models.Model): orders = self.env['purchase.order.line'].search( [('account_analytic_id', '=', rec.analytic_account_id.id), ('order_id.state', 'in', ['draft', 'sent', 'to approve'])]).mapped('order_id') - total_orders = sum(orders.mapped('amount_total')) - rec.reserve = total_orders * -1 - - @api.depends('planned_amount', 'provide', 'pull_out') - def _compute_final_amount(self): - for rec in self: - rec.final_amount = rec.planned_amount + rec.provide + rec.pull_out - - @api.depends('from_operation_ids') - def _compute_pull_out(self): - for line in self: - operations = self.env['budget.operations'].search( - [('from_budget_line_id', '=', line.id), ('state', '=', 'confirmed')]) - - pull_out = sum(op.amount + op.purchase_remind for op in - operations.filtered(lambda x: x.state == 'confirmed') if - op.operation_type == 'transfer' or op.operation_type == 'decrease') - line.pull_out = pull_out if line.planned_amount < 0 else pull_out * -1 + orders_without_tax = sum(orders.mapped('amount_total')) - sum(orders.mapped('amount_tax')) + need_tax = 0 + for line in orders.mapped('order_line'): + vals = line._prepare_compute_all_values() + taxes = line.taxes_id.filtered(lambda x: x.analytic).compute_all( + vals['price_unit'], + vals['currency_id'], + vals['product_qty'], + vals['product'], + vals['partner']) + need_tax += sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])) + rec.reserve = (orders_without_tax + need_tax) * -1 @api.depends('to_operation_ids') def _compute_provide(self): @@ -198,9 +201,7 @@ class CrossoveredBudgetLines(models.Model): ('account_id', 'in',line.general_budget_id.account_ids.ids), ('date', '>=', date_from), ('date', '<=', date_to), - ('move_id.state', '=', 'posted'), - ('move_id.move_type', '=', 'in_invoice') - ]) + ('move_id.state', '=', 'posted')]) total_amount = 0 for item in analytic_ids: tax_id = item.tax_ids[0].analytic if item.tax_ids else False diff --git a/odex25_accounting/exp_budget_check/i18n/ar_001.po b/odex25_accounting/exp_budget_check/i18n/ar_001.po index 945c6df85..e82a5e4d7 100644 --- a/odex25_accounting/exp_budget_check/i18n/ar_001.po +++ b/odex25_accounting/exp_budget_check/i18n/ar_001.po @@ -186,7 +186,7 @@ msgstr "الدفعات" #: code:addons/exp_budget_check/models/hr_expense.py:0 #, python-format msgid "Please Check Budget First" -msgstr "" +msgstr "برجاء التحقق من الضريبة" #. module: exp_budget_check #: code:addons/exp_budget_check/models/account_invoice.py:0 diff --git a/odex25_accounting/exp_budget_check/models/account_budget.py b/odex25_accounting/exp_budget_check/models/account_budget.py index 94878cb33..ef1844357 100644 --- a/odex25_accounting/exp_budget_check/models/account_budget.py +++ b/odex25_accounting/exp_budget_check/models/account_budget.py @@ -14,11 +14,21 @@ class CrossoveredBudgetLines(models.Model): for rec in self: orders = self.env['purchase.order.line'].search( [('account_analytic_id', '=', rec.analytic_account_id.id), - ('order_id.state', 'in', ['purchase','done'])]).mapped('order_id') - total_orders = sum(orders.mapped('amount_total')) + ('order_id.state', 'in', ['purchase', 'done'])]).mapped('order_id') + orders_without_tax = sum(orders.mapped('amount_total')) - sum(orders.mapped('amount_tax')) + need_tax = 0 + for line in orders.mapped('order_line'): + vals = line._prepare_compute_all_values() + taxes = line.taxes_id.filtered(lambda x: x.analytic).compute_all( + vals['price_unit'], + vals['currency_id'], + vals['product_qty'], + vals['product'], + vals['partner']) + need_tax += sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])) invoiced = self.env['account.move'].search( [('purchase_id', 'in', orders.ids), ('state', 'not in', ['draft', 'cancel'])]).mapped('amount_total') - rec.confirm = (total_orders - sum(invoiced)) * -1 + rec.confirm = ((orders_without_tax + need_tax) - sum(invoiced)) * -1 @api.depends('analytic_account_id') def _compute_reserve(self): @@ -26,8 +36,18 @@ class CrossoveredBudgetLines(models.Model): orders = self.env['purchase.order.line'].search( [('account_analytic_id', '=', rec.analytic_account_id.id), ('order_id.state', 'in', ['draft', 'sent', 'to approve'])]).mapped('order_id') - total_orders = sum(orders.mapped('amount_total')) - rec.reserve = total_orders * -1 + orders_without_tax = sum(orders.mapped('amount_total')) - sum(orders.mapped('amount_tax')) + need_tax = 0 + for line in orders.mapped('order_line'): + vals = line._prepare_compute_all_values() + taxes = line.taxes_id.filtered(lambda x: x.analytic).compute_all( + vals['price_unit'], + vals['currency_id'], + vals['product_qty'], + vals['product'], + vals['partner']) + need_tax += sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])) + rec.reserve = (orders_without_tax + need_tax) * -1 def _compute_operations_amount(self): if not self.ids: return diff --git a/odex25_accounting/exp_budget_check/models/hr_expense.py b/odex25_accounting/exp_budget_check/models/hr_expense.py index ee24ab1b7..f2e5af442 100644 --- a/odex25_accounting/exp_budget_check/models/hr_expense.py +++ b/odex25_accounting/exp_budget_check/models/hr_expense.py @@ -153,38 +153,39 @@ class AccountMove(models.Model): ('crossovered_budget_id.date_from', '<=', self.date), ('crossovered_budget_id.date_to', '>=', self.date)]) - if not budget_lines: - raise UserError(_('Analytic account %s is not linked with budget') % self.analytic_account_id.name) - else: - budget_line = budget_lines - remain = abs(budget_line.remain) + budget_line = budget_lines + if budget_line: + remain = abs(budget_line.remain) if budget_line else 0 tax_id = self.tax_ids[0].analytic if self.tax_ids else False price_before_tax= self.unit_amount* self.quantity tax_price = self.total_amount - price_before_tax amount = price_before_tax + (tax_price if tax_id else 0) new_remain = remain - amount - data = { - 'name': _('Expense: %s') % self.employee_id.name, - 'date': self.date, - 'beneficiary_id': self.employee_id.user_id.partner_id.id, - 'type': 'expense', - 'ref': self.name, - 'description': self.name, - 'total_amount': amount, - 'lines_ids': [(0, 0, { - 'amount': amount, - 'analytic_account_id': self.analytic_account_id.id, - 'description': self.product_id.name, - 'budget_line_id': budget_line.id, - 'remain': new_remain + amount, - 'new_balance': new_remain, - 'account_id': self.account_id.id - })], - 'expense_id': self.id - } - self.env['budget.confirmation'].create(data) + else: + new_remain = 0 + amount=0 + data = { + 'name': _('Expense: %s') % self.employee_id.name, + 'date': self.date, + 'beneficiary_id': self.employee_id.user_id.partner_id.id, + 'type': 'expense', + 'ref': self.name, + 'description': self.name, + 'total_amount': amount, + 'lines_ids': [(0, 0, { + 'amount': amount, + 'analytic_account_id': self.analytic_account_id.id, + 'description': self.product_id.name, + 'budget_line_id': budget_line.id if budget_line else False, + 'remain': new_remain + amount, + 'new_balance': new_remain, + 'account_id': self.account_id.id + })] if budget_line else False, + 'expense_id': self.id + } + self.env['budget.confirmation'].create(data) - self.write({ - 'is_check': True, - 'state': 'wait_budget' - }) + self.write({ + 'is_check': True, + 'state': 'wait_budget' + })