0

I'm getting RuntimeError: maximum recursion depth exceeded error and it's because of the line "'account_id','not in'" what can i do about it?

            @api.multi
            def to_invoice(self):
                    pos_order = self.env['pos.order'].search([('id','=',self._context.get('active_id'))])

                for line in pos_order.lines:
                domain3 = [
                    ('move_id', '=', pos_order.account_move.id),
                    ('credit', '=', pos_order.amount_tax),
                    ('account_id','not in', [pos_order.lines.tax_ids_after_fiscal_position, pos_order.lines.product_id.categ_id.property_account_income_categ_id])
            ]
                    if pos_order.amount_tax > 0:
                        move_line = 
self.env['account.move.line'].search(domain3)
                        print move_line
                    move_line[0].unlink()
Chaban33
  • 1,362
  • 11
  • 38
  • Do you know how maximum recursion occurs? – Navi Jun 18 '18 at 08:09
  • no, i just do know it occurs when it hits ('account_id','not in', [pos_order.lines.tax_ids_after_fiscal_position, pos_order.lines.product_id.categ_id.property_account_income_categ_id]) line – Chaban33 Jun 18 '18 at 08:10
  • It causes because of the loop which calculates so many times for account_id. Better add a condition like, once if your value is achieved, put a break at the end of the condition, so that the loop will stop once the correct value is achieved. – Navi Jun 18 '18 at 08:12
  • yeh i tried to put break in the end but didn't help. can you give example how this code should look? – Chaban33 Jun 18 '18 at 08:17

2 Answers2

1

Try like this:

@api.multi

def to_invoice(self):
   pos_order = self.env['pos.order'].search([('id','=',self._context.get('active_id'))])

   for line in pos_order.lines:
       domain3 = [
                    ('move_id', '=', pos_order.account_move.id),
                    ('credit', '=', pos_order.amount_tax),
                    ('account_id','not in', [pos_order.lines.tax_ids_after_fiscal_position, pos_order.lines.product_id.categ_id.property_account_income_categ_id])
                 ]
        if pos_order.amount_tax > 0:
           move_line = self.env['account.move.line'].search(domain3)
           print move_line
           move_line[0].unlink()
        break
Navi
  • 1,000
  • 1
  • 14
  • 44
0

This line should be

('account_id','not in', [line.tax_ids_after_fiscal_position.id, line.product_id.categ_id.property_account_income_categ_id.id])

Chaban33
  • 1,362
  • 11
  • 38