Browse Source

[FIX] Workaround to obtain max_date in account_partial_reconcile

pull/391/head
mreficent 7 years ago
parent
commit
912d5b5e25
  1. 38
      customer_activity_statement/report/customer_activity_statement.py
  2. 47
      customer_outstanding_statement/report/customer_outstanding_statement.py

38
customer_activity_statement/report/customer_activity_statement.py

@ -119,6 +119,35 @@ class CustomerActivityStatement(models.AbstractModel):
res[row.pop('partner_id')].append(row) res[row.pop('partner_id')].append(row)
return res return res
def _get_credit_date(self):
return """
SELECT apr.id, aml.date as credit_date
FROM account_partial_reconcile apr
LEFT JOIN account_move_line aml
ON aml.id = apr.credit_move_id
"""
def _get_debit_date(self):
return """
SELECT apr.id, aml.date as debit_date
FROM account_partial_reconcile apr
LEFT JOIN account_move_line aml
ON aml.id = apr.debit_move_id
"""
def _get_reconcile_date(self):
return """
SELECT pr2.id,
CASE WHEN Q0a.credit_date > Q0b.debit_date
THEN Q0a.credit_date
ELSE Q0b.debit_date
END AS max_date
FROM account_partial_reconcile pr2
LEFT JOIN (%s) as Q0a ON Q0a.id = pr2.id
LEFT JOIN (%s) as Q0b ON Q0b.id = pr2.id
GROUP BY pr2.id, Q0a.credit_date, Q0b.debit_date
""" % (self._get_credit_date(), self._get_debit_date())
def _show_buckets_sql_q0(self, date_end): def _show_buckets_sql_q0(self, date_end):
return """ return """
SELECT l1.id, SELECT l1.id,
@ -129,20 +158,23 @@ class CustomerActivityStatement(models.AbstractModel):
ELSE null ELSE null
END as reconciled_date END as reconciled_date
FROM account_move_line l1 FROM account_move_line l1
LEFT JOIN (SELECT pr.*
LEFT JOIN (SELECT pr.*, Q0c.max_date
FROM account_partial_reconcile pr FROM account_partial_reconcile pr
INNER JOIN account_move_line l2 INNER JOIN account_move_line l2
ON pr.credit_move_id = l2.id ON pr.credit_move_id = l2.id
LEFT JOIN (%s) as Q0c ON Q0c.id = pr.id
WHERE l2.date <= '%s' WHERE l2.date <= '%s'
) as pd ON pd.debit_move_id = l1.id ) as pd ON pd.debit_move_id = l1.id
LEFT JOIN (SELECT pr.*
LEFT JOIN (SELECT pr.*, Q0c.max_date
FROM account_partial_reconcile pr FROM account_partial_reconcile pr
INNER JOIN account_move_line l2 INNER JOIN account_move_line l2
ON pr.debit_move_id = l2.id ON pr.debit_move_id = l2.id
LEFT JOIN (%s) as Q0c ON Q0c.id = pr.id
WHERE l2.date <= '%s' WHERE l2.date <= '%s'
) as pc ON pc.credit_move_id = l1.id ) as pc ON pc.credit_move_id = l1.id
GROUP BY l1.id GROUP BY l1.id
""" % (date_end, date_end)
""" % (self._get_reconcile_date(), date_end,
self._get_reconcile_date(), date_end)
def _show_buckets_sql_q1(self, partners, date_end): def _show_buckets_sql_q1(self, partners, date_end):
return """ return """

47
customer_outstanding_statement/report/customer_outstanding_statement.py

@ -30,20 +30,23 @@ class CustomerOutstandingStatement(models.AbstractModel):
ELSE null ELSE null
END as reconciled_date END as reconciled_date
FROM account_move_line l1 FROM account_move_line l1
LEFT JOIN (SELECT pr.*
LEFT JOIN (SELECT pr.*, Q0c.max_date
FROM account_partial_reconcile pr FROM account_partial_reconcile pr
INNER JOIN account_move_line l2 INNER JOIN account_move_line l2
ON pr.credit_move_id = l2.id ON pr.credit_move_id = l2.id
LEFT JOIN (%s) as Q0c ON Q0c.id = pr.id
WHERE l2.date <= '%s' WHERE l2.date <= '%s'
) as pd ON pd.debit_move_id = l1.id ) as pd ON pd.debit_move_id = l1.id
LEFT JOIN (SELECT pr.*
LEFT JOIN (SELECT pr.*, Q0c.max_date
FROM account_partial_reconcile pr FROM account_partial_reconcile pr
INNER JOIN account_move_line l2 INNER JOIN account_move_line l2
ON pr.debit_move_id = l2.id ON pr.debit_move_id = l2.id
LEFT JOIN (%s) as Q0c ON Q0c.id = pr.id
WHERE l2.date <= '%s' WHERE l2.date <= '%s'
) as pc ON pc.credit_move_id = l1.id ) as pc ON pc.credit_move_id = l1.id
GROUP BY l1.id GROUP BY l1.id
""" % (date_end, date_end)
""" % (self._get_reconcile_date(), date_end,
self._get_reconcile_date(), date_end)
def _display_lines_sql_q1(self, partners, date_end): def _display_lines_sql_q1(self, partners, date_end):
return """ return """
@ -135,6 +138,35 @@ class CustomerOutstandingStatement(models.AbstractModel):
res[row.pop('partner_id')].append(row) res[row.pop('partner_id')].append(row)
return res return res
def _get_credit_date(self):
return """
SELECT apr.id, aml.date as credit_date
FROM account_partial_reconcile apr
LEFT JOIN account_move_line aml
ON aml.id = apr.credit_move_id
"""
def _get_debit_date(self):
return """
SELECT apr.id, aml.date as debit_date
FROM account_partial_reconcile apr
LEFT JOIN account_move_line aml
ON aml.id = apr.debit_move_id
"""
def _get_reconcile_date(self):
return """
SELECT pr2.id,
CASE WHEN Q0a.credit_date > Q0b.debit_date
THEN Q0a.credit_date
ELSE Q0b.debit_date
END AS max_date
FROM account_partial_reconcile pr2
LEFT JOIN (%s) as Q0a ON Q0a.id = pr2.id
LEFT JOIN (%s) as Q0b ON Q0b.id = pr2.id
GROUP BY pr2.id, Q0a.credit_date, Q0b.debit_date
""" % (self._get_credit_date(), self._get_debit_date())
def _show_buckets_sql_q0(self, date_end): def _show_buckets_sql_q0(self, date_end):
return """ return """
SELECT l1.id, SELECT l1.id,
@ -145,20 +177,23 @@ class CustomerOutstandingStatement(models.AbstractModel):
ELSE null ELSE null
END as reconciled_date END as reconciled_date
FROM account_move_line l1 FROM account_move_line l1
LEFT JOIN (SELECT pr.*
LEFT JOIN (SELECT pr.*, Q0c.max_date
FROM account_partial_reconcile pr FROM account_partial_reconcile pr
INNER JOIN account_move_line l2 INNER JOIN account_move_line l2
ON pr.credit_move_id = l2.id ON pr.credit_move_id = l2.id
LEFT JOIN (%s) as Q0c ON Q0c.id = pr.id
WHERE l2.date <= '%s' WHERE l2.date <= '%s'
) as pd ON pd.debit_move_id = l1.id ) as pd ON pd.debit_move_id = l1.id
LEFT JOIN (SELECT pr.*
LEFT JOIN (SELECT pr.*, Q0c.max_date
FROM account_partial_reconcile pr FROM account_partial_reconcile pr
INNER JOIN account_move_line l2 INNER JOIN account_move_line l2
ON pr.debit_move_id = l2.id ON pr.debit_move_id = l2.id
LEFT JOIN (%s) as Q0c ON Q0c.id = pr.id
WHERE l2.date <= '%s' WHERE l2.date <= '%s'
) as pc ON pc.credit_move_id = l1.id ) as pc ON pc.credit_move_id = l1.id
GROUP BY l1.id GROUP BY l1.id
""" % (date_end, date_end)
""" % (self._get_reconcile_date(), date_end,
self._get_reconcile_date(), date_end)
def _show_buckets_sql_q1(self, partners, date_end): def _show_buckets_sql_q1(self, partners, date_end):
return """ return """

Loading…
Cancel
Save