Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd

I have a module that create new tax to invoice for cash payment mode; 

the tax is added to move.lines but it's value not added to receivable account to get a balanced move.


ERROR:

The move (Draft Invoice INV/2024/00002) is not balanced. The total of debits equals 416.50 DA and the total of credits equals 421.50 DA. You might want to specify a default account on journal "Customer Invoices" to automatically balance each move. 


following is a code:

   def ks_update_timbre_fiscal_dz_15(self):
for rec in self:
already_exists = self.line_ids.filtered(
lambda line: line.name and line.name.find('Timbre Fiscal') == 0)
terms_lines = self.line_ids.filtered(
lambda line: line.account_id.account_type in ('asset_receivable', 'liability_payable'))

other_lines = self.line_ids.filtered(
lambda line: line.account_id.account_type not in ('asset_receivable', 'liability_payable'))
if already_exists:
amount = rec.ks_amount_global_tax
if rec.ks_sales_tax_account_id \
and (rec.move_type == "out_invoice"
or rec.move_type == "out_refund")\
and rec.ks_global_tax_rate > 0:
if rec.move_type == "out_invoice":
already_exists.update({
'debit': amount 'credit': amount > 0.0 and amount or 0.0,
})
else:
already_exists.update({
'debit': amount > 0.0 and amount or 0.0,
'credit': amount })
else:
already_exists.update({
'debit': amount 'credit': amount > 0.0 and amount or 0.0,
})
total_balance = sum(other_lines.mapped('balance'))
total_amount_currency = sum(other_lines.mapped('amount_currency'))
terms_lines.update({
'amount_currency': -total_amount_currency,
'debit': total_balance 'credit': total_balance > 0.0 and total_balance or 0.0,
})
if not already_exists and rec.ks_global_tax_rate > 0:
in_draft_mode = self != self._origin
if not in_draft_mode:
rec._recompute_timbre_fiscal_dz_15_lines()

@api.onchange('ks_global_tax_rate', 'line_ids')
def _recompute_timbre_fiscal_dz_15_lines(self):
for rec in self:
type_list = ['out_invoice', 'out_refund', 'in_invoice', 'in_refund']
if rec.ks_global_tax_rate > 0 and rec.move_type in type_list:
if rec.is_invoice(include_receipts=True):
in_draft_mode = self != self._origin
ks_name = "Timbre Fiscal"
ks_name = ks_name + \
" @" + str(self.ks_global_tax_rate) + "%"
terms_lines = self.line_ids.filtered(
lambda line: line.account_id.account_type in ('asset_receivable', 'liability_payable'))


already_exists = self.line_ids.filtered(
lambda line: line.name and line.name.find('Timbre Fiscal') == 0)
if already_exists:
amount = self.ks_amount_global_tax
if self.ks_sales_tax_account_id \
and (self.move_type == "out_invoice"
or self.move_type == "out_refund"):
already_exists.update({
'name': ks_name,
'debit': amount 'credit': amount > 0.0 and amount or 0.0,
})

else:
new_tax_line = self.env['account.move.line']
create_method = in_draft_mode and \
self.env['account.move.line'].new or\
self.env['account.move.line'].create

if self.ks_sales_tax_account_id \
and (self.move_type == "out_invoice"
or self.move_type == "out_refund"):
amount = self.ks_amount_global_tax
dict = {
'move_name': self.name,
'name': ks_name,
'price_unit': self.ks_amount_global_tax,
'quantity': 1,
'debit': amount 'credit': amount > 0.0 and amount or 0.0,
'account_id': self.ks_sales_tax_account_id,
'move_id': self._origin,
'date': self.date,
'partner_id': terms_lines.partner_id.id,
'company_id': terms_lines.company_id.id,
'company_currency_id': terms_lines.company_currency_id.id,
}
if self.move_type == "out_invoice":
dict.update({

'debit': amount 'credit': amount > 0.0 and amount or 0.0,
})
else:
dict.update({
'debit': amount > 0.0 and amount or 0.0,
'credit': amount })
if in_draft_mode:
self.line_ids += create_method(dict)
# Updation of Invoice Line Id
duplicate_id = self.invoice_line_ids.filtered(
lambda line: line.name and line.name.find('Timbre Fiscal') == 0)
self.invoice_line_ids = self.invoice_line_ids - duplicate_id
else:
dict.update({
'price_unit': 0.0,
'debit': 0.0,
'credit': 0.0,
})
self.line_ids = [(0, 0, dict)]


if self.move_type == "in_invoice":
dict.update({
'debit': amount > 0.0 and amount or 0.0,
'credit': amount })
else:
dict.update({
'debit': amount 'credit': amount > 0.0 and amount or 0.0,
})
self.line_ids += create_method(dict)
# updation of invoice line id
duplicate_id = self.invoice_line_ids.filtered(
lambda line: line.name and line.name.find('Timbre Fiscal') == 0)
self.invoice_line_ids = self.invoice_line_ids - duplicate_id

if in_draft_mode:
# Update the payement account amount
terms_lines = self.line_ids.filtered(
lambda line: line.account_id.account_type in ('asset_receivable', 'liability_payable'))
other_lines = self.line_ids.filtered(
lambda line: line.account_id.account_type not in ('asset_receivable', 'liability_payable'))

total_balance = sum(other_lines.mapped('balance'))
total_amount_currency = sum(other_lines.mapped('amount_currency'))
terms_lines.update({
'amount_currency': -total_amount_currency,
'debit': total_balance 'credit': total_balance > 0.0 and total_balance or 0.0,
})
else:
terms_lines = self.line_ids.filtered(
lambda line: line.account_id.account_type in ('asset_receivable', 'liability_payable'))
other_lines = self.line_ids.filtered(
lambda line: line.account_id.account_type not in ('asset_receivable', 'liability_payable'))
already_exists = self.line_ids.filtered(
lambda line: line.name and line.name.find('Timbre Fiscal') == 0)
total_balance = sum(other_lines.mapped('balance')) - amount
total_amount_currency = sum(other_lines.mapped('amount_currency'))
dict1 = {
'debit': amount 'credit': amount > 0.0 and amount or 0.0,
}
dict2 = {
'debit': total_balance 'credit': total_balance > 0.0 and total_balance or 0.0,
}
if terms_lines:
self.line_ids = [(1, already_exists.id, dict1), (1, terms_lines[0].id, dict2)]
print()

elif self.ks_global_tax_rate already_exists = self.line_ids.filtered(
lambda line: line.name and line.name.find('Timbre Fiscal') == 0)
if already_exists:
self.line_ids -= already_exists
terms_lines = self.line_ids.filtered(
lambda line: line.account_id.account_type in ('asset_receivable', 'liability_payable'))
other_lines = self.line_ids.filtered(
lambda line: line.account_id.account_type not in ('asset_receivable', 'liability_payable'))
total_balance = sum(other_lines.mapped('balance'))
total_amount_currency = sum(other_lines.mapped('amount_currency'))
terms_lines.update({
'amount_currency': -total_amount_currency,
'debit': total_balance 'credit': total_balance > 0.0 and total_balance or 0.0,
})


Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
feb. 24
1215
1
feb. 23
1675
1
aug. 21
3280
0
mrt. 15
4109
4
feb. 24
2771