parent
5b412f6150
commit
5aa91616f6
45
sale.py
45
sale.py
@ -126,53 +126,36 @@ class Sale(metaclass=PoolMeta):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_residual_amount(cls, sales, names):
|
def get_residual_amount(cls, sales, name):
|
||||||
return {n: {s.id: s.total_amount - s.paid_amount if s.state != 'cancel'
|
return {s.id: s.total_amount - s.paid_amount if s.state in (
|
||||||
else Decimal(0) for s in sales} for n in names}
|
'confirmed', 'processing', 'done') else
|
||||||
|
Decimal(0) for s in sales}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def search_residual_amount(cls, name, clause):
|
def search_residual_amount(cls, name, clause):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Sale = pool.get('sale.sale')
|
Sale = pool.get('sale.sale')
|
||||||
SaleLine = pool.get('sale.line')
|
|
||||||
Invoice = pool.get('account.invoice')
|
|
||||||
InvoiceLine = pool.get('account.invoice.line')
|
|
||||||
StatementLine = pool.get('account.statement.line')
|
StatementLine = pool.get('account.statement.line')
|
||||||
|
|
||||||
sale = Sale.__table__()
|
sale = Sale.__table__()
|
||||||
saleline = SaleLine.__table__()
|
payline = StatementLine.__table__()
|
||||||
invoice = Invoice.__table__()
|
Operator = fields.SQL_OPERATORS[clause[1]]
|
||||||
invoiceline = InvoiceLine.__table__()
|
value = clause[2]
|
||||||
line = StatementLine.__table__()
|
|
||||||
|
|
||||||
grouped = sale.join(
|
query = sale.join(
|
||||||
line,
|
payline,
|
||||||
type_='LEFT',
|
type_='LEFT',
|
||||||
condition=(sale.id == line.sale)
|
condition=(sale.id == payline.sale)
|
||||||
).select(
|
).select(
|
||||||
sale.id,
|
sale.id,
|
||||||
where=((sale.total_amount_cache != None) &
|
where=((sale.total_amount_cache != None) &
|
||||||
(sale.state.in_(['confirmed', 'processing', 'done']))),
|
(sale.state.in_(['confirmed', 'processing', 'done']))),
|
||||||
group_by=(sale.id),
|
group_by=(sale.id),
|
||||||
having=(
|
having=(
|
||||||
Sum(Coalesce(line.amount, 0)) < sale.total_amount_cache))
|
(Sum(Coalesce(payline.amount, 0)) < sale.total_amount_cache)
|
||||||
|
& Operator(sale.total_amount_cache -
|
||||||
query = grouped.join(
|
Sum(Coalesce(payline.amount, 0)), value)
|
||||||
saleline,
|
))
|
||||||
condition=(saleline.sale == grouped.id)
|
|
||||||
).join(
|
|
||||||
invoiceline,
|
|
||||||
condition=(Cast(Substring(invoiceline.origin,
|
|
||||||
Position(',', invoiceline.origin) + Literal(1)),
|
|
||||||
SaleLine.id.sql_type().base) == saleline.id)
|
|
||||||
).join(
|
|
||||||
invoice,
|
|
||||||
condition=(invoice.id == invoiceline.invoice)
|
|
||||||
).select(
|
|
||||||
grouped.id,
|
|
||||||
where=(invoice.state == 'posted'),
|
|
||||||
group_by=(grouped.id)
|
|
||||||
)
|
|
||||||
|
|
||||||
return [('id', 'in', query)]
|
return [('id', 'in', query)]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user