我想计算account.bank.statement
上“Montantcrédit”列的总和。我尝试使用_get_sum_entry_encoding,但那些不起作用。
见图:
答案 0 :(得分:0)
尝试以下代码:
def _get_tot(self, cr, uid, ids, name, arg, context=None):
res = {}
cr.execute("SELECT sum(amount) FROM account_bank_statement_line WHERE statement_id ="+str(ids)+"")
data = cr.fetchall()
for re in self.browse(cr, uid, ids, context=context):
res[re.id] = data
return res
答案 1 :(得分:0)
from openerp.osv import fields, orm, osv
class sale_order_line(orm.Model):
_inherit = 'account.bank.statement'
_name = 'account.bank.statement'
def _get_tot(self, cr, uid, ids, name, arg, context=None):
res = {}
cr.execute("SELECT sum(amount) FROM account_bank_statement_line WHERE statement_id ="+str(ids[0])+"")
data = cr.fetchone()
for re in self.browse(cr, uid, ids, context=context):
res[re.id] = data[0]
return res
def _get_statement_from_line(self, cr, uid, ids, context=None):
result = {}
for line in self.pool.get('account.bank.statement.line').browse(cr, uid, ids, context=context):
result[line.statement_id.id] = True
return result.keys()
_columns = {
'totm': fields.function(_get_tot, 'totm',type='float',
store = {
'account.bank.statement': (lambda self, cr, uid, ids, context=None: ids, ['line_ids','move_line_ids'], 10),
'account.bank.statement.line': (_get_statement_from_line, ['amount'], 10),
}),
}
.xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_order_form_ftz">
<field name="name">view.order.form.ftz</field>
<field name="model">account.bank.statement</field>
<field name="inherit_id" ref="account.view_bank_statement_formfz" />
<field name="arch" type="xml">
<xpath expr="//field[@name='balance_start']" position="after">
<field name="totm" string="Montant total"/>
</xpath>
</field>
</record>
</data>
</openerp>
我想你再次卡比尔。