ACCOUNT_PAYMENT: added '_id(s)

bzr revid: bch-d523aa43ffab31f169f9a641ff784a8de451fef5
This commit is contained in:
bch 2007-08-07 12:02:12 +00:00
parent 9630076822
commit c42b1b14c2
4 changed files with 34 additions and 35 deletions

View File

@ -35,7 +35,7 @@ class account_move_line(osv.osv):
""" Return the amount still to pay regarding all the payemnt orders (excepting cancelled orders)""" """ Return the amount still to pay regarding all the payemnt orders (excepting cancelled orders)"""
if not ids: if not ids:
return {} return {}
cr.execute("SELECT ml.id,ml.credit - (select coalesce(sum(amount),0) from payment_line pl inner join payment_order po on (pl.order = po.id)where move_line = ml.id and po.state != 'cancel') as amount from account_move_line ml where credit > 0 and id in (%s)"% (",".join(map(str,ids)))) cr.execute("SELECT ml.id,ml.credit - (select coalesce(sum(amount),0) from payment_line pl inner join payment_order po on (pl.order_id = po.id)where move_line_id = ml.id and po.state != 'cancel') as amount from account_move_line ml where credit > 0 and id in (%s)"% (",".join(map(str,ids))))
r=dict(cr.fetchall()) r=dict(cr.fetchall())
return r return r
@ -46,8 +46,8 @@ class account_move_line(osv.osv):
query = self.pool.get('account.move.line')._query_get(cr, uid, context={}) query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
where = ' and '.join(map(lambda x: '''(select l.credit - coalesce(sum(amount),0) where = ' and '.join(map(lambda x: '''(select l.credit - coalesce(sum(amount),0)
from payment_line pl from payment_line pl
inner join payment_order po on (pl.order = po.id) inner join payment_order po on (pl.order_id = po.id)
where move_line = l.id and po.state != 'cancel') '''+x[1]+str(x[2])+' ',args)) where move_line_id = l.id and po.state != 'cancel') '''+x[1]+str(x[2])+' ',args))
cr.execute(('''select id cr.execute(('''select id
from account_move_line l from account_move_line l

View File

@ -50,7 +50,7 @@ class payment_mode(osv.osv):
_columns= { _columns= {
'name': fields.char('Name', size=64, required=True), 'name': fields.char('Name', size=64, required=True),
'code': fields.char('Code', size=64, required=True,unique=True,select=True), 'code': fields.char('Code', size=64, required=True,unique=True,select=True),
'bank': fields.many2one('res.partner.bank',"Bank account",required=True), 'bank_id': fields.many2one('res.partner.bank',"Bank account",required=True),
'journal': fields.many2one('account.journal','Journal',required=True,domain=[('type','=','cash')]), 'journal': fields.many2one('account.journal','Journal',required=True,domain=[('type','=','cash')]),
'type': fields.many2one('payment.type','Payment type',required=True), 'type': fields.many2one('payment.type','Payment type',required=True),
} }
@ -75,17 +75,17 @@ class payment_order(osv.osv):
def _total(self, cr, uid, ids, name, args, context={}): def _total(self, cr, uid, ids, name, args, context={}):
if not ids: return {} if not ids: return {}
cr.execute("""select l.order, coalesce(sum(amount),0) cr.execute("""select o.id, coalesce(sum(amount),0)
from payment_order_line l from payment_order o left join payment_line l on (o.id = l.order_id)
where l.order in (%s) group by l.order"""% ','.join(map(str,ids))) where o.id in (%s) group by o.id"""% ','.join(map(str,ids)))
return dict(cr.fetchall()) return dict(cr.fetchall())
def nb_line(self, cr, uid, ids, name, args, context={}): def nb_line(self, cr, uid, ids, name, args, context={}):
if not ids: return {} if not ids: return {}
res= {}.fromkeys(ids,0) res= {}.fromkeys(ids,0)
cr.execute("""select "order",count(*) cr.execute("""select "order_id",count(*)
from payment_line from payment_line
where "order" in (%s) group by "order" """% ','.join(map(str,ids))) where "order_id" in (%s) group by "order_id" """% ','.join(map(str,ids)))
res.update(dict(cr.fetchall())) res.update(dict(cr.fetchall()))
return res return res
@ -101,7 +101,7 @@ class payment_order(osv.osv):
'mode': fields.selection(mode_get, 'Payment mode',size=16,required=True, select=True), 'mode': fields.selection(mode_get, 'Payment mode',size=16,required=True, select=True),
'state': fields.selection([('draft', 'Draft'),('open','Open'), 'state': fields.selection([('draft', 'Draft'),('open','Open'),
('cancel','Cancelled'),('done','Done')], 'State', select=True), ('cancel','Cancelled'),('done','Done')], 'State', select=True),
'lines': fields.one2many('payment.line','order','Payment lines'), 'line_ids': fields.one2many('payment.line','order_id','Payment lines'),
'total': fields.function(_total, string="Total", method=True, type='float'), 'total': fields.function(_total, string="Total", method=True, type='float'),
'user_id': fields.many2one('res.users','User',required=True), 'user_id': fields.many2one('res.users','User',required=True),
'nb_line': fields.function(nb_line,string='Number of payment',method=True, type='integer'), 'nb_line': fields.function(nb_line,string='Number of payment',method=True, type='integer'),
@ -141,12 +141,12 @@ payment_order()
class payment_line(osv.osv): class payment_line(osv.osv):
_name = 'payment.line' _name = 'payment.line'
_description = 'Payment Line' _description = 'Payment Line'
_rec_name = 'move_line' _rec_name = 'move_line_id'
def partner_payable(self, cr, uid, ids, name, args, context={}): def partner_payable(self, cr, uid, ids, name, args, context={}):
if not ids: return {} if not ids: return {}
partners= self.read(cr, uid, ids, ['partner'], context) partners= self.read(cr, uid, ids, ['partner_id'], context)
partners= dict(map(lambda x: (x['id'],x['partner']),partners)) partners= dict(map(lambda x: (x['id'],x['partner_id']),partners))
debit= self.pool.get('res.partner')._debit_get(cr, uid, partners.values(), name, args, context) debit= self.pool.get('res.partner')._debit_get(cr, uid, partners.values(), name, args, context)
for i in partners: for i in partners:
partners[i]= debit[partners[i]] partners[i]= debit[partners[i]]
@ -155,40 +155,39 @@ class payment_line(osv.osv):
def translate(self,orig): def translate(self,orig):
return {"to_pay":"credit", return {"to_pay":"credit",
"due_date":"date_maturity", "due_date":"date_maturity",
"partner":"partner_id",
"reference":"ref"}.get(orig,orig) "reference":"ref"}.get(orig,orig)
def select_by_name(self, cr, uid, ids, name, args, context={}): def select_by_name(self, cr, uid, ids, name, args, context={}):
if not ids: return {} if not ids: return {}
cr.execute("""SELECT pl.id, ml.%s cr.execute("""SELECT pl.id, ml.%s
from account_move_line ml from account_move_line ml
inner join payment_line pl on (ml.id= pl.move_line) inner join payment_line pl on (ml.id= pl.move_line_id)
where pl.id in (%s)"""% (self.translate(name),','.join(map(str,ids))) ) where pl.id in (%s)"""% (self.translate(name),','.join(map(str,ids))) )
return dict(cr.fetchall()) return dict(cr.fetchall())
_columns = { _columns = {
'move_line': fields.many2one('account.move.line','Entry line',required=True), 'move_line_id': fields.many2one('account.move.line','Entry line',required=True),
'amount': fields.float('Payment Amount', digits=(16,2), required=True), 'amount': fields.float('Payment Amount', digits=(16,2), required=True),
'bank': fields.many2one('res.partner.bank','Bank account'), 'bank_id': fields.many2one('res.partner.bank','Bank account'),
'order': fields.many2one('payment.order','Order', ondelete='cascade', select=True), 'order_id': fields.many2one('payment.order','Order', ondelete='cascade', select=True),
'partner': fields.function(select_by_name, string="Partner", method=True, type='many2one', obj='res.partner'), 'partner_id': fields.function(select_by_name, string="Partner", method=True, type='many2one', obj='res.partner'),
'to_pay': fields.function(select_by_name, string="To pay", method=True, type='float'), 'to_pay': fields.function(select_by_name, string="To pay", method=True, type='float'),
'due_date': fields.function(select_by_name, string="Due date", method=True, type='date'), 'due_date': fields.function(select_by_name, string="Due date", method=True, type='date'),
'date_created': fields.function(select_by_name, string="Creation date", method=True, type='date'), 'date_created': fields.function(select_by_name, string="Creation date", method=True, type='date'),
'reference': fields.function(select_by_name, string="Ref", method=True, type='char'), 'reference': fields.function(select_by_name, string="Ref", method=True, type='char'),
'partner_payable': fields.function(partner_payable, string="Partner payable", method=True, type='float'), 'partner_payable': fields.function(partner_payable, string="Partner payable", method=True, type='float'),
} }
def onchange_move_line(self, cr, uid, id, move_line, type,context={}): def onchange_move_line(self, cr, uid, id, move_line_id, type,context={}):
if not move_line: if not move_line_id:
return {} return {}
line=self.pool.get('account.move.line').browse(cr,uid,move_line) line=self.pool.get('account.move.line').browse(cr,uid,move_line_id)
return {'value': {'amount': line.amount_to_pay, return {'value': {'amount': line.amount_to_pay,
'to_pay': line.amount_to_pay, 'to_pay': line.amount_to_pay,
'partner': line.partner_id, 'partner_id': line.partner_id,
'reference': line.ref, 'reference': line.ref,
'date_created': line.date_created, 'date_created': line.date_created,
'bank': self.pool.get('account.move.line').line2bank(cr,uid,[move_line],type,context)[move_line] 'bank_id': self.pool.get('account.move.line').line2bank(cr,uid,[move_line_id],type,context)[move_line_id]
}} }}
payment_line() payment_line()

View File

@ -46,7 +46,7 @@
<field name="code" select="1"/> <field name="code" select="1"/>
<field name="type" /> <field name="type" />
<field name="journal" /> <field name="journal" />
<field name="bank" /> <field name="bank_id" />
</form> </form>
</field> </field>
</record> </record>
@ -70,7 +70,7 @@
<field name="date_planned" select="1"/> <field name="date_planned" select="1"/>
<field name="user_id" select="2"/> <field name="user_id" select="2"/>
<button name="%(wizard_payment)d" string="Add payment lines" type="action" colspan="2"/> <button name="%(wizard_payment)d" string="Add payment lines" type="action" colspan="2"/>
<field name="lines" colspan="4" nolabel="1"/> <field name="line_ids" colspan="4" nolabel="1"/>
<field name="total"/> <field name="total"/>
<field name="nb_line"/> <field name="nb_line"/>
<field name="date_created" select="2"/> <field name="date_created" select="2"/>
@ -150,11 +150,11 @@
<field name="type">form</field> <field name="type">form</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Payment Line"> <form string="Payment Line">
<field name="move_line" select="1" on_change="onchange_move_line(move_line,parent.mode)" domain="[('reconcile_id','=', False), ('credit', '>',0),('amount_to_pay','>',0)] "/> <field name="move_line_id" select="1" on_change="onchange_move_line(move_line_id,parent.mode)" domain="[('reconcile_id','=', False), ('credit', '>',0),('amount_to_pay','>',0)] "/>
<field name="amount" select="1" /> <field name="amount" select="1" />
<field name="bank" domain="[('partner_id','=',partner)]"/> <field name="bank_id" domain="[('partner_id','=',partner_id)]"/>
<field name="to_pay"/> <field name="to_pay"/>
<field name="partner"/> <field name="partner_id"/>
<field name="partner_payable"/> <field name="partner_payable"/>
<field name="reference"/> <field name="reference"/>
<field name="due_date"/> <field name="due_date"/>
@ -169,11 +169,11 @@
<field name="priority" eval="4"/> <field name="priority" eval="4"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Payment Line" editable="bottom" colors="red:to_pay&lt;amount" > <tree string="Payment Line" editable="bottom" colors="red:to_pay&lt;amount" >
<field name="move_line" select="1" on_change="onchange_move_line(move_line,parent.mode)" domain="[('reconcile_id','=', False), ('credit', '>',0),('amount_to_pay','>',0)] "/> <field name="move_line_id" select="1" on_change="onchange_move_line(move_line_id,parent.mode)" domain="[('reconcile_id','=', False), ('credit', '>',0),('amount_to_pay','>',0)] "/>
<field name="bank" domain="[('partner_id','=',partner)]"/> <field name="bank_id" domain="[('partner_id','=',partner_id)]"/>
<field name="amount"/> <field name="amount"/>
<field name="to_pay"/> <field name="to_pay"/>
<field name="partner"/> <field name="partner_id"/>
<field name="partner_payable"/> <field name="partner_payable"/>
<field name="reference"/> <field name="reference"/>
<field name="due_date"/> <field name="due_date"/>

View File

@ -71,10 +71,10 @@ def create_payment(self, cr, uid, data, context):
## Finally populate the current payment with new lines: ## Finally populate the current payment with new lines:
for line in pool.get('account.move.line').browse(cr,uid,mline_ids,context=context): for line in pool.get('account.move.line').browse(cr,uid,mline_ids,context=context):
pool.get('payment.line').create(cr,uid,{ pool.get('payment.line').create(cr,uid,{
'move_line': line.id, 'move_line_id': line.id,
'amount':line.amount_to_pay, 'amount':line.amount_to_pay,
'bank':line2bank.get(line.id), 'bank_id':line2bank.get(line.id),
'order': payment['id'], 'order_id': payment['id'],
}) })
return {} return {}