Skip to Content
Menu
This question has been flagged
1073 Views

I'm using bahmni-0.93 with odoo-10.


When I press Confirm button in the Sale Order and skip/cancel the Register Payment step, the Total Outstanding amount is getting calculated as double the actual amount.

Here, the Previous Balance field is taking the amount in the current sale order, and then this value is also getting added to the Net Amount.


When I check the bahmni-erp/bahmni-addons/bahmni_sale/models/sale_order.py, I observe this code under SaleOrder class


prev_outstanding_balance = fields.Monetary(string="Previous Outstanding Balance",
                                               compute=_calculate_balance)
total_outstanding_balance = fields.Monetary(string="Total Outstanding Balance",
                                                compute=_amount_all)

def _calculate_balance(self):
    for order in self:
        order.prev_outstanding_balance = 0.0
        order.total_outstanding_balance = 0.0
        total_receivable = order._total_receivable()
        order.prev_outstanding_balance = total_receivable

def _amount_all(self):
        """
        Compute the total amounts of the SO.
        """
        for order in self:
            ...
            order.update({
                'amount_untaxed': order.pricelist_id.currency_id.round(amount_untaxed),
                'amount_tax': order.pricelist_id.currency_id.round(amount_tax),
                'amount_total': amount_total + round_off_amount,
                'round_off_amount': round_off_amount,
                'total_outstanding_balance': order.prev_outstanding_balance + amount_total + round_off_amount
            })

def _total_receivable(self):
    receivable = 0.0
    if self.partner_id:
        self._cr.execute("""SELECT l.partner_id, at.type, SUM(l.debit-l.credit)
                      FROM account_move_line l
                      LEFT JOIN account_account a ON (l.account_id=a.id)
                      LEFT JOIN account_account_type at ON (a.user_type_id=at.id)
                      WHERE at.type IN ('receivable','payable')
                      AND l.partner_id = %s
                      AND l.full_reconcile_id IS NULL
                      GROUP BY l.partner_id, at.type
                      """, (self.partner_id.id,))
        for pid, type, val in self._cr.fetchall():
            if val is None:
                val=0
            receivable = (type == 'receivable') and val or -val
    return receivable

Why it's adding the Net Amount of the current Sale Order to the prev_outstanding_balance?

How do I solve this?

Thanks.

Avatar
Discard
Related Posts Replies Views Activity
0
May 20
2496
2
Jan 19
28020
3
Jul 18
4849
2
Nov 24
25096
2
Nov 24
476