Merge lp:~julie-w/unifield-server/US-1275 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 3745
Proposed branch: lp:~julie-w/unifield-server/US-1275
Merge into: lp:unifield-server
Diff against target: 122 lines (+63/-33)
1 file modified
bin/addons/register_accounting/invoice.py (+63/-33)
To merge this branch: bzr merge lp:~julie-w/unifield-server/US-1275
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+293502@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/register_accounting/invoice.py'
2--- bin/addons/register_accounting/invoice.py 2016-03-23 09:57:20 +0000
3+++ bin/addons/register_accounting/invoice.py 2016-05-02 07:53:11 +0000
4@@ -37,36 +37,54 @@
5 if args and args[0] and len(args[0]) == 3:
6 if args[0][1] != '=':
7 raise osv.except_osv(_('Error'), _('Operator not supported yet!'))
8- # Search all imported invoice
9- sql = """SELECT INV_ID, INV_TOTAL, abs(SUM(absl.amount))
10- FROM (
11- SELECT inv.id AS INV_ID, inv.amount_total AS INV_TOTAL, aml.id AS AML
12- FROM account_invoice inv, account_move_line aml, account_move am
13- WHERE inv.move_id = am.id
14- AND aml.move_id = am.id
15- AND inv.state = 'open'
16- ORDER BY inv.id
17- ) AS move_lines, imported_invoice imp, account_bank_statement_line absl
18- WHERE imp.move_line_id = move_lines.AML
19- AND imp.st_line_id = absl.id
20- GROUP BY INV_ID, INV_TOTAL"""
21 # Fetch second args (type of import)
22 s = args[0][2]
23- # Complete SQL query if needed
24- if s == 'imported':
25- sql += """ HAVING INV_TOTAL = abs(SUM(absl.amount))"""
26- elif s == 'partial':
27- sql += """ HAVING INV_TOTAL != abs(SUM(absl.amount))"""
28- # finish SQL query
29- sql += """ ORDER BY INV_ID;"""
30+ if s == 'not':
31+ # (US-1275) Display only the invoices "draft", or "open" but not yet partially or fully imported
32+ sql = """SELECT id FROM
33+ (
34+ SELECT id FROM account_invoice
35+ WHERE state = 'draft'
36+ UNION
37+ SELECT inv.id
38+ FROM account_invoice inv
39+ INNER JOIN account_move am ON inv.move_id = am.id
40+ INNER JOIN account_move_line aml ON aml.move_id = am.id
41+ WHERE inv.state = 'open'
42+ AND ABS(aml.amount_residual_import_inv - inv.amount_total) < 0.001
43+ AND aml.is_counterpart = 't'
44+ AND aml.account_id = inv.account_id
45+ AND aml.move_id = inv.move_id
46+ ) AS draft_and_not_imported
47+ ORDER BY id;"""
48+ else:
49+ # Search all imported invoices
50+ sql = """SELECT INV_ID, INV_TOTAL, RESIDUAL
51+ FROM (
52+ SELECT inv.id AS INV_ID, inv.amount_total AS INV_TOTAL, aml.id AS AML, aml.amount_residual_import_inv AS RESIDUAL
53+ FROM account_invoice inv
54+ INNER JOIN account_move am ON inv.move_id = am.id
55+ INNER JOIN account_move_line aml ON aml.move_id = am.id
56+ WHERE inv.state = 'open'
57+ AND aml.is_counterpart = 't'
58+ AND aml.account_id = inv.account_id
59+ AND aml.move_id = inv.move_id
60+ ORDER BY inv.id
61+ ) AS move_lines, imported_invoice imp
62+ WHERE imp.move_line_id = move_lines.AML
63+ GROUP BY INV_ID, INV_TOTAL, RESIDUAL"""
64+ # Complete SQL query if needed
65+ having = ''
66+ if s == 'imported':
67+ having = ' HAVING RESIDUAL <= 0.001'
68+ elif s == 'partial':
69+ having = ' HAVING RESIDUAL > 0.001 AND RESIDUAL < INV_TOTAL'
70+ # finish SQL query
71+ sql = ''.join((sql, having, ' ORDER BY INV_ID;'))
72 # execution
73 cr.execute(sql)
74 sql_res = cr.fetchall()
75- # process regarding second args
76- if s in ['partial', 'imported']:
77- res = [('id', 'in', [x and x[0] for x in sql_res])]
78- else:
79- res = [('id', 'not in', [x and x[0] for x in sql_res])]
80+ res = [('id', 'in', [x and x[0] for x in sql_res])]
81 return res
82
83 def _get_imported_state(self, cr, uid, ids, field_name=None, arg=None, context=None):
84@@ -80,18 +98,30 @@
85 if not context:
86 context = {}
87 res = {}
88+ acc_ml_obj = self.pool.get('account.move.line')
89+ acc_obj = self.pool.get('account.account')
90+ acc_list = acc_obj.search(cr, uid, [('type', 'in', ['payable', 'receivable'])])
91 for inv in self.browse(cr, uid, ids, context):
92 res[inv.id] = 'none'
93 if inv.move_id:
94- absl_ids = self.pool.get('account.bank.statement.line').search(cr, uid, [('imported_invoice_line_ids', 'in', [x.id for x in inv.move_id.line_id])])
95- if absl_ids:
96+ absl_ids = self.pool.get('account.bank.statement.line').search(cr, uid, [('imported_invoice_line_ids', 'in', [x.id for x in inv.move_id.line_id])], context=context)
97+ account = inv.account_id
98+ if absl_ids and account and (account.id in acc_list):
99 res[inv.id] = 'imported'
100- if isinstance(absl_ids, (int, long)):
101- absl_ids = [absl_ids]
102- if inv.amount_total != sum([x and abs(x.amount) or 0.0 for x in self.pool.get('account.bank.statement.line').browse(cr, uid, absl_ids)]):
103- res[inv.id] = 'partial'
104- continue
105- res[inv.id] = 'not'
106+ acc_ml_id = acc_ml_obj.search(cr, uid, [('account_id', '=', account.id),
107+ ('is_counterpart', '=', True),
108+ ('move_id', '=', inv.move_id.id)], context=context)
109+ acc_ml = acc_ml_obj.browse(cr, uid, acc_ml_id, context)
110+ if acc_ml:
111+ residual = acc_ml[0].amount_residual_import_inv
112+ if residual and abs(residual - inv.amount_total) < 0.001:
113+ res[inv.id] = 'not'
114+ elif residual and residual < inv.amount_total and residual > 0.001:
115+ res[inv.id] = 'partial'
116+ else:
117+ res[inv.id] = 'not'
118+ else:
119+ res[inv.id] = 'not'
120 return res
121
122 def _get_down_payment_ids(self, cr, uid, ids, field_name=None, arg=None, context=None):

Subscribers

People subscribed via source and target branches