
from odoo import api, models


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

    @api.onchange(
        "amount_currency",
        "currency_id",
        "debit",
        "credit",
        "tax_ids",
        "account_id",
        "analytic_account_id",
        "analytic_tag_ids",
    )
    def _onchange_mark_recompute_taxes(self):
        for line in self:
            if line.purchase_line_id.usage_id.account_id:
                account = line.purchase_line_id.usage_id.account_id
            else:
                account = line._get_computed_account()
            line.account_id = account
        return super(AccountMoveLine, self)._onchange_mark_recompute_taxes()


from odoo import api, models


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

    @api.onchange(
        "amount_currency",
        "currency_id",
        "debit",
        "credit",
        "tax_ids",
        "account_id",
        "analytic_account_id",
        "analytic_tag_ids",
    )
    def _onchange_mark_recompute_taxes(self):
        for line in self:
            if line.purchase_line_id.usage_id.account_id:
                line.account_id = line.purchase_line_id.usage_id.account_id
        return super(AccountMoveLine, self)._onchange_mark_recompute_taxes()

Change only account if usage is defined in POL
[13.0][FIX] purchase_product_usage: Change only account if usage is defined in POL

  
  from odoo import api, models
  
  
  class AccountMoveLine(models.Model):
      _inherit = "account.move.line"
  
      @api.onchange(
          "amount_currency",
          "currency_id",
          "debit",
          "credit",
          "tax_ids",
          "account_id",
          "analytic_account_id",
          "analytic_tag_ids",
      )
      def _onchange_mark_recompute_taxes(self):
          for line in self:
              if line.purchase_line_id.usage_id.account_id:
-                 account = line.purchase_line_id.usage_id.account_id
+                 line.account_id = line.purchase_line_id.usage_id.account_id
-             else:
-                 account = line._get_computed_account()
-             line.account_id = account
          return super(AccountMoveLine, self)._onchange_mark_recompute_taxes()
  
Change only account if usage is defined in POL
## Code Before:

from odoo import api, models


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

    @api.onchange(
        "amount_currency",
        "currency_id",
        "debit",
        "credit",
        "tax_ids",
        "account_id",
        "analytic_account_id",
        "analytic_tag_ids",
    )
    def _onchange_mark_recompute_taxes(self):
        for line in self:
            if line.purchase_line_id.usage_id.account_id:
                account = line.purchase_line_id.usage_id.account_id
            else:
                account = line._get_computed_account()
            line.account_id = account
        return super(AccountMoveLine, self)._onchange_mark_recompute_taxes()

## Instruction:
Change only account if usage is defined in POL
## Code After:

from odoo import api, models


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

    @api.onchange(
        "amount_currency",
        "currency_id",
        "debit",
        "credit",
        "tax_ids",
        "account_id",
        "analytic_account_id",
        "analytic_tag_ids",
    )
    def _onchange_mark_recompute_taxes(self):
        for line in self:
            if line.purchase_line_id.usage_id.account_id:
                line.account_id = line.purchase_line_id.usage_id.account_id
        return super(AccountMoveLine, self)._onchange_mark_recompute_taxes()
