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

i'm trying to cancel the advance payment which is created against the payment which is conformed 

inherited the account.payment and override the action_draft payment method, i have passed the current payment reference into advance payment while creating advance payment

here is my code for canceling the advance payment

def action_draft(self):
    moves = self.mapped('move_line_ids.move_id')
    moves.filtered(lambda move: move.state == 'posted').button_draft()
    moves.with_context(force_delete=True).unlink()
    self.write({'state': 'draft', 'invoice_ids': False})
    advance_payment = self.search([('base_payment_id', '=', self.id),
                                           ('payment_category', '=', 'advance_payment'), ('state', '=', 'posted')])
    if advance_payment:
          advance_payment.action_draft()
          advance_payment.cancel()

this code work fine and cancel the advance payment but its give warning

Comparing Apples and oranges


形象
丢弃
最佳答案

Hi, 

This error occurs when you are comparing two unrelated things say, objects and id

Example: purchase.order(1,) == 15      ## In this case it throws kinda error

I guess the error is here,  ('payment_category', '=', 'advance_payment')

Thanks.


形象
丢弃
编写者

Comparing apples and oranges: account.payment(82,) == 82

Sorry typo error...it should be model( 15,) == 15 nd thanks

编写者

its okay but can you please elaborate this because i'm searching record set of account.payment in account.payment model and still did not get the point.

or any other way to do this thing

Hi,

advance_payment variable should be declared before using in domain . what model does payment_category points to ?

For many2one comparision

it should be ('many2one_field', '=', many2one_field.id)

For many2many comparision

it should be ('many2one_field', 'in', many2many.ids)

相关帖文 回复 查看 活动
1
5月 21
13534
1
7月 20
3686
4
5月 24
12655
1
4月 24
3282
0
11月 23
2032