在odoo中,我需要列出所有已支付的订单,但不完全(因此所有订单都是第一次发布)。 我使用此代码扩展了sale_order类,但它不起作用(我没有错误消息)
class sale(osv.osv):
def _invoiced_search(self, cursor, user, obj, name, args, context=None):
if not len(args):
return []
clause = ''
sale_clause = ''
no_invoiced = False
for arg in args:
if (arg[1] == '=' and arg[2]) or (arg[1] == '!=' and not arg[2]):
clause += 'AND inv.state = \'open\' AND inv.residual != \'0.0\' AND inv.residual != inv.amount_total '
else:
clause += 'AND inv.state != \'cancel\' AND sale.state != \'cancel\' AND inv.state = \'paid\' AND rel.order_id = sale.id '
clause += 'AND inv.state = \'open\' AND inv.residual != \'0.0\' AND inv.residual != inv.amount_total '
sale_clause = ', sale_order AS sale '
clause += 'AND inv.state = \'open\' AND inv.residual = inv.amount_total'
no_invoiced = True
cursor.execute('SELECT rel.order_id ' \
'FROM sale_order_invoice_rel AS rel, account_invoice AS inv '+ sale_clause + \
'WHERE rel.invoice_id = inv.id ' + clause)
res = cursor.fetchall()
if no_invoiced:
cursor.execute('SELECT sale.id ' \
'FROM sale_order AS sale ' \
'WHERE sale.id NOT IN ' \
'(SELECT rel.order_id ' \
'FROM sale_order_invoice_rel AS rel) ' \
'AND sale.state != \'cancel\'')
res.extend(cursor.fetchall())
if not res:
return [('id', '=', 0)]
return [('id', 'in', [x[0] for x in res])]
def _partial_invoiced(self, cursor, user, ids, name, arg, context=None):
res = {}
for sale in self.browse(cursor, user, ids, context=context):
res[sale.id] = False
invoice_existence = False
for invoice in sale.invoice_ids:
if invoice.state!='cancel':
invoice_existence = True
if invoice.state == 'open' and invoice.residual != '0.0':
res[sale.id] = True
break
if not invoice_existence or sale.state == 'manual':
res[sale.id] = False
return res
_inherit = 'sale.order'
_columns = {
'partially_invoiced': fields.function(_partial_invoiced, string='Paid',
fnct_search=_invoiced_search, type='boolean', help="It indicates that an invoice is partially paid."),
}
帮助;)