跳至内容
菜单
此问题已终结
1 回复
6152 查看

I created this wizard to add custom invoice in 'pos.order':

import wizard
import pooler
from tools.translate import _

class link_invoice(wizard.interface):

    def _show_report(self, cr, uid, data, context):
        pos_obj = pooler.get_pool(cr.dbname).get('pos.order')
        found = False
        for pos in pos_obj.browse(cr, uid, data['ids'], context = context):
            for inv in pos.invoice_id:
                if inv.state != 'cancel':
                    found = True
                    break
                    continue
        if not found:
            raise wizard.except_wizard(_('Error'), _('POS has no related invoices.'))
        return {
            'report_name': 'invoice.with_picking_lists',
            'type': 'ir.actions.report.xml' }

    states = {
        'init': {
            'actions': [],
            'result': {
                'type': 'action',
                'action': _show_report,
                'state': 'end' } } }

link_invoice('pos.order.invoice.with_picking_lists')

When I try to open invoice, I get this error:

KeyError: "Field '0' does not exist in object 'browse_record(pos.order, 8)'"
形象
丢弃
最佳答案

hey Andrius

this part of code should be :

 for pos in pos_obj.browse(cr, uid, data['ids'], context = context):
       #for inv in pos.invoice_id:
       if inv.invoice_id.state != 'cancel':
           found = True
           break

remember invoice_id is an many2one field so you can directly get state of that invoive like this invoice_id.state

thanks
sandeep

形象
丢弃
编写者

Thanks, but I it should be pos.invoice_id.state, because inv is not assigned (when it is commented). I tried it, but now I'm getting this error: local variable 'objects' referenced before assignment

相关帖文 回复 查看 活动
2
7月 24
2905
2
4月 24
2762
4
10月 20
5704
0
8月 19
3331
4
8月 19
4542