Skip to Content
Menu
This question has been flagged
2 Replies
10178 Views

My Original code in sale_analytic.py

class AccountAnalyticLine(models.Model):

_inherit = "account.analytic.line"

@api.multi

def write(self, values):

if self._context.get('create', False):

return super(AccountAnalyticLine, self).write(values)

todo = self.mapped('so_line')

result = super(AccountAnalyticLine, self).write(values)

if 'so_line' in values:

todo |= self.mapped('so_line')

for line in self:

res = self._get_sale_order_line(vals=values)

super(AccountAnalyticLine, line).write(res)

if 'so_line' in res:

todo |= line.mapped('so_line')

todo._compute_analytic()

return result

Here I have an new file named sample.py

I have inherited same class.

class AccountAnalyticLine(models.Model):

_inherit = "account.analytic.line"

@api.multi

def write(self, values):

if self._context.get('create', False):

return super(AccountAnalyticLine, self).write(values)

todo = self.mapped('so_line')

result = super(AccountAnalyticLine, self).write(values)

if 'so_line' in values:

todo |= self.mapped('so_line')

for line in self:

res = line._get_sale_order_line(vals=values)

super(AccountAnalyticLine, line).write(res)

if 'so_line' in res:

todo |= line.mapped('so_line')

todo._compute_analytic()

return result

Instead of this line "res = self._get_sale_order_line(vals=values)" I need to change it as

"res = line._get_sale_order_line(vals=values)"

Can anyone please help me?

Avatar
Discard
Best Answer

res = line.sudo()._get_sale_order_line(vals=values)

Avatar
Discard
Best Answer

I believe, for loop is not need,

But if you insist upon have it, no issues, However the called function api decorator should match it.

If you want to call the method _get_sale_order_line, for each and every record,  ensure you have added decorator as api.one, that way you can make a call individually for each record in the For Loop

@api.one
def _get_sale_order_line(self, vals)

in source obj

for line in self:
    res = line._get_sale_order_line(vals=values)

Else keep it has api.multi, and make a call without the help of For Loop.

@api.multi
def _get_sale_order_line(self, vals)

 accordingly in source obj:

res = self._get_sale_order_line(vals=values)

Note:

you are performing your action in the ORM Write method, of type multi, however be aware, not always self._ids will be array/multiple, chances are there it can be singleton record/id. Hence Ensure before proceeding with you action.

Avatar
Discard
Related Posts Replies Views Activity
6
Oct 20
7536
0
Feb 17
1798
1
Jan 16
2953
1
Jan 16
5237
4
Jan 16
5202