fix confirm amount

This commit is contained in:
ronozoro 2024-10-28 23:19:22 -07:00
parent fa6e3d8259
commit 03ac489df3
No known key found for this signature in database
GPG Key ID: 7C2BDED35C62C0F3
2 changed files with 44 additions and 22 deletions

View File

@ -81,12 +81,17 @@ class CrossoveredBudgetLines(models.Model):
@api.depends('analytic_account_id')
def _compute_confirm(self):
for rec in self:
orders = self.env['purchase.order.line'].search(
order_lines = self.env['purchase.order.line'].search(
[('account_analytic_id', '=', rec.analytic_account_id.id),
('order_id.state', 'in', ['purchase', 'done'])]).mapped('order_id')
orders_without_tax = sum(orders.mapped('amount_total')) - sum(orders.mapped('amount_tax'))
('order_id.date_order', '>=', rec.crossovered_budget_id.date_from),
('order_id.date_order', '<=', rec.crossovered_budget_id.date_to),
'|', ('product_id.property_account_expense_id', 'in', rec.general_budget_id.account_ids.ids),
('product_id.categ_id.property_account_expense_categ_id', 'in', rec.general_budget_id.account_ids.ids),
('order_id.state', 'in', ['purchase', 'done'])])
orders_without_tax = sum(order_lines.mapped('price_subtotal'))
need_tax = 0
for line in orders.mapped('order_line'):
invoice_amount = 0
for line in order_lines:
vals = line._prepare_compute_all_values()
taxes = line.taxes_id.filtered(lambda x: x.analytic).compute_all(
vals['price_unit'],
@ -95,19 +100,25 @@ class CrossoveredBudgetLines(models.Model):
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 = ((orders_without_tax + need_tax) - sum(invoiced)) * -1
invoiced = self.env['account.move.line'].search(
[('purchase_line_id', '=', line.id), ('move_id.state', 'not in', ['draft', 'cancel'])])
invoice_amount += sum(invoiced.mapped('price_subtotal')) if not need_tax else sum(
invoiced.mapped('move_id.amount_total'))
rec.confirm = ((orders_without_tax + need_tax) - invoice_amount) * -1
@api.depends('analytic_account_id')
def _compute_reserve(self):
for rec in self:
orders = self.env['purchase.order.line'].search(
order_lines = 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')
orders_without_tax = sum(orders.mapped('amount_total')) - sum(orders.mapped('amount_tax'))
('order_id.date_order', '>=', rec.crossovered_budget_id.date_from),
('order_id.date_order', '<=', rec.crossovered_budget_id.date_to),
'|', ('product_id.property_account_expense_id', 'in', rec.general_budget_id.account_ids.ids),
('product_id.categ_id.property_account_expense_categ_id', 'in', rec.general_budget_id.account_ids.ids),
('order_id.state', 'in', ['draft', 'sent', 'to approve'])])
orders_without_tax = sum(order_lines.mapped('price_subtotal'))
need_tax = 0
for line in orders.mapped('order_line'):
for line in order_lines:
vals = line._prepare_compute_all_values()
taxes = line.taxes_id.filtered(lambda x: x.analytic).compute_all(
vals['price_unit'],

View File

@ -12,12 +12,17 @@ class CrossoveredBudgetLines(models.Model):
@api.depends('analytic_account_id')
def _compute_confirm(self):
for rec in self:
orders = self.env['purchase.order.line'].search(
order_lines = self.env['purchase.order.line'].search(
[('account_analytic_id', '=', rec.analytic_account_id.id),
('order_id.state', 'in', ['purchase', 'done'])]).mapped('order_id')
orders_without_tax = sum(orders.mapped('amount_total')) - sum(orders.mapped('amount_tax'))
('order_id.date_order', '>=', rec.crossovered_budget_id.date_from),
('order_id.date_order', '<=', rec.crossovered_budget_id.date_to),
'|', ('product_id.property_account_expense_id', 'in', rec.general_budget_id.account_ids.ids),
('product_id.categ_id.property_account_expense_categ_id', 'in', rec.general_budget_id.account_ids.ids),
('order_id.state', 'in', ['purchase', 'done'])])
orders_without_tax = sum(order_lines.mapped('price_subtotal'))
need_tax = 0
for line in orders.mapped('order_line'):
invoice_amount = 0
for line in order_lines:
vals = line._prepare_compute_all_values()
taxes = line.taxes_id.filtered(lambda x: x.analytic).compute_all(
vals['price_unit'],
@ -26,19 +31,25 @@ class CrossoveredBudgetLines(models.Model):
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 = ((orders_without_tax + need_tax) - sum(invoiced)) * -1
invoiced = self.env['account.move.line'].search(
[('purchase_line_id', '=', line.id), ('move_id.state', 'not in', ['draft', 'cancel'])])
invoice_amount += sum(invoiced.mapped('price_subtotal')) if not need_tax else sum(
invoiced.mapped('move_id.amount_total'))
rec.confirm = ((orders_without_tax + need_tax) - invoice_amount) * -1
@api.depends('analytic_account_id')
def _compute_reserve(self):
for rec in self:
orders = self.env['purchase.order.line'].search(
order_lines = 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')
orders_without_tax = sum(orders.mapped('amount_total')) - sum(orders.mapped('amount_tax'))
('order_id.date_order', '>=', rec.crossovered_budget_id.date_from),
('order_id.date_order', '<=', rec.crossovered_budget_id.date_to),
'|', ('product_id.property_account_expense_id', 'in', rec.general_budget_id.account_ids.ids),
('product_id.categ_id.property_account_expense_categ_id', 'in', rec.general_budget_id.account_ids.ids),
('order_id.state', 'in', ['draft', 'sent', 'to approve'])])
orders_without_tax = sum(order_lines.mapped('price_subtotal'))
need_tax = 0
for line in orders.mapped('order_line'):
for line in order_lines:
vals = line._prepare_compute_all_values()
taxes = line.taxes_id.filtered(lambda x: x.analytic).compute_all(
vals['price_unit'],