跳至內容
選單
此問題已被標幟
1 回覆
7713 瀏覽次數

something wrong happened in account moves as adding an analytic account to journal items of vendor bills and I need to loop on all lines in account moves and remove the analytic account from all lines by this bit of code 

class NewModule(models.Model):
_inherit = 'account.move'

def analytic(self):
    all=self.env['account.move'].search([('type','=','in_invoice')])
    ana=all.line_ids.mapped('analytic_account_id')
    ana.unlink()

but when this method run I get this error "The operation cannot be completed: another model requires the record being deleted. If possible, archive it instead. Model: Analytic Line (account.analytic.line), Constraint: account_analytic_line_account_id_fkey"

otherwise if tried to remove the analytic account for UI it removed without any issues but there is too many bills to do it manually

any help will be appreciated

頭像
捨棄
最佳答案

Hi,

Try change your code like below.

def analytic(self):
self.env['account.move'].search([('type', 'in', ('out_invoice', 'in_invoice'))]).line_ids.write(
{'analytic_account_id': [(5, 0, 0)]})

Regards

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
2月 22
2933
0
6月 21
36
0
10月 24
3753
2
11月 15
8698
1
3月 15
9642