32
32
logger=netsvc.Logger()
34
from operator import itemgetter
35
class account_move_line(osv.osv):
36
_inherit = "account.move.line"
38
def amount_to_pay(self, cr, uid, ids, name, arg={}, context=None):
39
""" Return the amount still to pay regarding all the payment orders
40
(excepting cancelled orders)"""
43
cr.execute("""SELECT ml.id,
44
CASE WHEN ml.amount_currency < 0
45
THEN - ml.amount_currency
48
(SELECT coalesce(sum(amount_currency),0)
50
INNER JOIN payment_order po
51
ON (pl.order_id = po.id)
52
WHERE move_line_id = ml.id
53
AND po.state != 'cancel') AS amount
54
FROM account_move_line ml
55
WHERE id IN %s""", (tuple(ids),))
56
r = dict(cr.fetchall())
59
def _to_pay_search(self, cr, uid, obj, name, args, context=None):
62
line_obj = self.pool.get('account.move.line')
63
query = line_obj._query_get(cr, uid, context={})
64
where = ' and '.join(map(lambda x: '''(SELECT
65
CASE WHEN l.amount_currency < 0
66
THEN - l.amount_currency
68
END - coalesce(sum(pl.amount_currency), 0)
70
INNER JOIN payment_order po ON (pl.order_id = po.id)
71
WHERE move_line_id = l.id
72
AND po.state != 'cancel'
73
) %(operator)s %%s ''' % {'operator': x[1]}, args))
74
sql_args = tuple(map(itemgetter(2), args))
76
cr.execute(('''SELECT id
77
FROM account_move_line l
78
WHERE account_id IN (select id
80
WHERE type in %s AND active)
81
AND reconcile_id IS null
83
AND ''' + where + ' and ' + query), (('payable','receivable'),)+sql_args ) # fix Noviat to include sale refunds
87
return [('id', '=', '0')]
88
return [('id', 'in', map(lambda x:x[0], res))]
91
'amount_to_pay': fields.function(amount_to_pay, method=True,
92
type='float', string='Amount to pay', fnct_search=_to_pay_search),
34
97
class payment_order_create(osv.osv_memory):
35
98
_inherit = 'payment.order.create'
45
108
data = self.read(cr, uid, ids, [], context=context)[0]
46
109
search_due_date = data['duedate']
47
110
# Search for move line to pay:
48
domain = [('reconcile_id', '=', False), ('account_id.type', '=', 'payable'), ('amount_to_pay', '>', 0)]
111
domain = [('reconcile_id', '=', False), ('account_id.type', 'in', ['payable', 'receivable']), ('amount_to_pay', '>', 0)] # update Noviat
49
112
domain = domain + ['|', ('date_maturity', '<=', search_due_date), ('date_maturity', '=', False)]
50
domain = domain + [('journal_id.type', '=', 'purchase')] #update Noviat
113
domain = domain + [('journal_id.type', 'in', ['purchase', 'sale_refund'])] # update Noviat
51
114
line_ids = line_obj.search(cr, uid, domain, context=context)
52
115
context.update({'line_ids': line_ids})
53
116
model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'view_create_payment_order_lines')], context=context)