[FIX] account: Only sum posted entries to compute amount_due for partners
-Create a random journal entry affecting the partner A, using a receivable/payable account. -Let the journal entry in draft. => The amount set on the line must not be sum in the partner's amount_due. closes odoo/odoo#36973 X-original-commit: 3ab4589ff444da9889ac922ac9d7ba6c8e8638bc Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
@@ -204,12 +204,12 @@ class ResPartner(models.Model):
|
||||
|
||||
@api.multi
|
||||
def _credit_debit_get(self):
|
||||
tables, where_clause, where_params = self.env['account.move.line'].with_context(company_id=self.env.user.company_id.id)._query_get()
|
||||
tables, where_clause, where_params = self.env['account.move.line'].with_context(state='posted', company_id=self.env.user.company_id.id)._query_get()
|
||||
where_params = [tuple(self.ids)] + where_params
|
||||
if where_clause:
|
||||
where_clause = 'AND ' + where_clause
|
||||
self._cr.execute("""SELECT account_move_line.partner_id, act.type, SUM(account_move_line.amount_residual)
|
||||
FROM account_move_line
|
||||
FROM """ + tables + """
|
||||
LEFT JOIN account_account a ON (account_move_line.account_id=a.id)
|
||||
LEFT JOIN account_account_type act ON (a.user_type_id=act.id)
|
||||
WHERE act.type IN ('receivable','payable')
|
||||
@@ -238,9 +238,11 @@ class ResPartner(models.Model):
|
||||
SELECT partner.id
|
||||
FROM res_partner partner
|
||||
LEFT JOIN account_move_line aml ON aml.partner_id = partner.id
|
||||
JOIN account_move move ON move.id = aml.move_id
|
||||
RIGHT JOIN account_account acc ON aml.account_id = acc.id
|
||||
WHERE acc.internal_type = %s
|
||||
AND NOT acc.deprecated AND acc.company_id = %s
|
||||
AND move.state == 'posted'
|
||||
GROUP BY partner.id
|
||||
HAVING %s * COALESCE(SUM(aml.amount_residual), 0) ''' + operator + ''' %s''', (account_type, self.env.user.company_id.id, sign, operand))
|
||||
res = self._cr.fetchall()
|
||||
@@ -308,7 +310,14 @@ class ResPartner(models.Model):
|
||||
partner.contracts_count = AccountAnalyticAccount.search_count([('partner_id', '=', partner.id)])
|
||||
|
||||
def get_followup_lines_domain(self, date, overdue_only=False, only_unblocked=False):
|
||||
domain = [('reconciled', '=', False), ('account_id.deprecated', '=', False), ('account_id.internal_type', '=', 'receivable'), '|', ('debit', '!=', 0), ('credit', '!=', 0), ('company_id', '=', self.env.user.company_id.id)]
|
||||
domain = [
|
||||
('reconciled', '=', False),
|
||||
('account_id.deprecated', '=', False),
|
||||
('account_id.internal_type', '=', 'receivable'),
|
||||
'|', ('debit', '!=', 0), ('credit', '!=', 0),
|
||||
('company_id', '=', self.env.user.company_id.id),
|
||||
('move_id.state', '=', 'posted'),
|
||||
]
|
||||
if only_unblocked:
|
||||
domain += [('blocked', '=', False)]
|
||||
if self.ids:
|
||||
|
||||
Reference in New Issue
Block a user