fix: update advance paid in SO/PO from Payment Ledger
This commit is contained in:
parent
c52b41d311
commit
4487065b67
@ -7,7 +7,7 @@ import json
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _, throw
|
from frappe import _, throw
|
||||||
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
|
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
|
||||||
from frappe.query_builder.functions import Sum
|
from frappe.query_builder.functions import Abs, Sum
|
||||||
from frappe.utils import (
|
from frappe.utils import (
|
||||||
add_days,
|
add_days,
|
||||||
add_months,
|
add_months,
|
||||||
@ -1334,30 +1334,20 @@ class AccountsController(TransactionBase):
|
|||||||
return stock_items
|
return stock_items
|
||||||
|
|
||||||
def set_total_advance_paid(self):
|
def set_total_advance_paid(self):
|
||||||
if self.doctype == "Sales Order":
|
ple = frappe.qb.DocType("Payment Ledger Entry")
|
||||||
dr_or_cr = "credit_in_account_currency"
|
party = self.customer if self.doctype == "Sales Order" else self.supplier
|
||||||
rev_dr_or_cr = "debit_in_account_currency"
|
advance = (
|
||||||
party = self.customer
|
frappe.qb.from_(ple)
|
||||||
else:
|
.select(ple.account_currency, Abs(Sum(ple.amount)).as_("amount"))
|
||||||
dr_or_cr = "debit_in_account_currency"
|
.where(
|
||||||
rev_dr_or_cr = "credit_in_account_currency"
|
(ple.against_voucher_type == self.doctype)
|
||||||
party = self.supplier
|
& (ple.against_voucher_no == self.name)
|
||||||
|
& (ple.party == party)
|
||||||
advance = frappe.db.sql(
|
& (ple.delinked == 0)
|
||||||
"""
|
& (ple.company == self.company)
|
||||||
select
|
)
|
||||||
account_currency, sum({dr_or_cr}) - sum({rev_dr_cr}) as amount
|
.run(as_dict=True)
|
||||||
from
|
)
|
||||||
`tabGL Entry`
|
|
||||||
where
|
|
||||||
against_voucher_type = %s and against_voucher = %s and party=%s
|
|
||||||
and docstatus = 1
|
|
||||||
""".format(
|
|
||||||
dr_or_cr=dr_or_cr, rev_dr_cr=rev_dr_or_cr
|
|
||||||
),
|
|
||||||
(self.doctype, self.name, party),
|
|
||||||
as_dict=1,
|
|
||||||
) # nosec
|
|
||||||
|
|
||||||
if advance:
|
if advance:
|
||||||
advance = advance[0]
|
advance = advance[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user