2

I tried to get the same field from purchase_order_line to account_move_line

class PurchaseLine(models.Model):
    _inherit = 'purchase.order.line'

task_id = fields.Many2one('project.task', string='Rubriques', store=True)

And i tried to override the method _prepare_account_move_line

class AccountMoveLine(models.Model):
    _inherit = "account.move.line"

task_id = fields.Many2one('project.task', string='Rubriques', store=True)

def _prepare_account_move_line(self, move):
    res = super(AccountMoveLine, self)._prepare_account_move_line(move)
    res.update({
        'task_id': self.order_id.task_id.id
    })
    return res

but that doesn't work do u have idea?

RIzu
  • 21
  • 3

1 Answers1

1

Your extension to _prepare_account_move_line has to be made on model purchase.order.line and you have a little mistake in it:

class PurchaseLine(models.Model):
    _inherit = "purchase.order.line"

    def _prepare_account_move_line(self, move):
        res = super(AccountMoveLine, self)._prepare_account_move_line(move)
        res.update({
            "task_id": self.task_id.id
        })
        return res

The little mistake was self.order_id.task_id.id which should be self.task_id.id because you've defined task_id directly on the purchase line where this method is called.

CZoellner
  • 13,553
  • 3
  • 25
  • 38
  • doesnt work sadly, i got the field but not the value in it :( – RIzu Dec 05 '22 at 18:02
  • I means thats work but i could like to get the same value, i should say it in my post :/ – RIzu Dec 05 '22 at 18:17
  • If you don't get the same value, then it obvisiouly does not work ;-) – CZoellner Dec 06 '22 at 08:37
  • Right now i don't the mistake in my solution :-/ – CZoellner Dec 06 '22 at 08:42
  • what do you mean by didnt get the same value, are you referring that the in invoice line the field is not shown and value is not getting stored ? – Sidharth Panda Dec 06 '22 at 11:34
  • @Sidharth Panda Yeah! In my purchase order line i selected "04 task" ( for exemple ) and in my account move line nothing, a empty field and i would like to got the same task – RIzu Dec 06 '22 at 12:29
  • IN account.move.line if you are adding a field then you also have to add that same field to journal entries line as well what i mean to say is in account.move.line you have ```invoice_line_ids``` and ```line_ids``` so you have to add the same field in both, after that you can store or do whatever you want in that field – Sidharth Panda Dec 07 '22 at 02:25