This question has been flagged

I am facing strange issue here..


I have added a global charge named SURCHARGE.
I have used added it everywhere wherever required as below:


def _compute_amount(self):
"""
Compute the total amounts and GST amount of the Invoice.
"""
self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line_ids)
self.amount_before_surcharge = self.amount_untaxed
self.fuel_surcharge_amt = self.amount_untaxed * self.fuel_surcharge/100

self.amount_untaxed += self.fuel_surcharge_amt
def get_taxes_values(self):
tax_grouped = {}
for line in self.invoice_line_ids:
price_bfc = line.price_unit * (1 - (line.discount or 0.0) / 100.0) + line.invoice_ins_charge
price_unit = price_bfc + (price_bfc* self.fuel_surcharge/100)
taxes = line.invoice_line_tax_ids.compute_all(price_unit, self.currency_id, line.quantity, line.product_id, self.partner_id)['taxes']
for tax in taxes:


Now, the Invoice Total amount due didnt show the price including the new surcharge, so added to residual as well.

def _compute_residual(self):
residual = 0.0
residual_company_signed = 0.0
sign = self.type in ['in_refund', 'out_refund'] and -1 or 1
for line in self.sudo().move_id.line_ids:
if line.account_id.internal_type in ('receivable', 'payable'):
residual_company_signed += line.amount_residual
if line.currency_id == self.currency_id:
residual += line.amount_residual_currency if line.currency_id else line.amount_residual
else:
from_currency = (line.currency_id and line.currency_id.with_context(date=line.date)) or line.company_id.currency_id.with_context(date=line.date)
residual += from_currency.compute(line.amount_residual, self.currency_id)


residual+=self.fuel_surcharge_amt
residual_company_signed += self.fuel_surcharge_amt

self.residual_company_signed = abs(residual_company_signed) * sign
self.residual_signed = abs(residual) * sign
self.residual = abs(residual)
digits_rounding_precision = self.currency_id.rounding
if float_is_zero(self.residual, precision_rounding=digits_rounding_precision):
self.reconciled = True
else:
self.reconciled = False


Now, after this the Invoice shows correct total everywhere untill I register payment.
Suppose my Invoice has total due as below


100.00 10.00

110.0019.80129.80
129.80


-----------------------------------

Now, when I register payment, It tells me total amount due as 129.80, I am able to make complete payment..

But after registering payment, the new amount structure is as below:

100.0010.00110.0019.80129.80


Paid on 08/20/2017 119.80 ₹
10.00

Outstanding credits
Add INV/2017/0019 10.00 ₹


The surchrge added is not taken in payment and it shows as amount due and credit amount.
Please help... what I am missing here.. ??







Avatar
Discard