prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  [14.0] account_payment_purchase: changing many2one resets payment_mode
  Hi,
  We've seen that when the field purchase_vendor_bill_id is changed and a purchase is selected from it, the payment_mode_id is always reseted because it is using the reference purchase_id.
  `new_mode = self.purchase_id.payment_mode_id.id or False`
  We've made this change, and it seems to work as it should.
  `new_mode = self.purchase_vendor_bill_id.purchase_order_id.payment_mode_id.id or False`
  The same goes for the partner_bank_id field.
  @MiquelRForgeFlow 
  
  </issue>
  <code>
  [start of account_payment_purchase/models/account_invoice.py]
  1 # Copyright 2016 Akretion (<http://www.akretion.com>).
  2 # Copyright 2017 Tecnativa - Vicent Cubells.
  3 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4 
  5 from odoo import _, api, models
  6 
  7 
  8 class AccountMove(models.Model):
  9     _inherit = "account.move"
  10 
  11     @api.onchange("purchase_vendor_bill_id", "purchase_id")
  12     def _onchange_purchase_auto_complete(self):
  13         new_mode = self.purchase_id.payment_mode_id.id or False
  14         new_bank = self.purchase_id.supplier_partner_bank_id.id or False
  15         res = super()._onchange_purchase_auto_complete() or {}
  16         if self.payment_mode_id and new_mode and self.payment_mode_id.id != new_mode:
  17             res["warning"] = {
  18                 "title": _("Warning"),
  19                 "message": _("Selected purchase order have different payment mode."),
  20             }
  21             return res
  22         self.payment_mode_id = new_mode
  23         if self.partner_bank_id and new_bank and self.partner_bank_id.id != new_bank:
  24             res["warning"] = {
  25                 "title": _("Warning"),
  26                 "message": _("Selected purchase order have different supplier bank."),
  27             }
  28             return res
  29         self.partner_bank_id = new_bank
  30         return res
  31
  [end of account_payment_purchase/models/account_invoice.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/account_payment_purchase/models/account_invoice.py b/account_payment_purchase/models/account_invoice.py
  --- a/account_payment_purchase/models/account_invoice.py
  +++ b/account_payment_purchase/models/account_invoice.py
  @@ -10,8 +10,16 @@
   
       @api.onchange("purchase_vendor_bill_id", "purchase_id")
       def _onchange_purchase_auto_complete(self):
  -        new_mode = self.purchase_id.payment_mode_id.id or False
  -        new_bank = self.purchase_id.supplier_partner_bank_id.id or False
  +
  +        new_mode = (
  +            self.purchase_vendor_bill_id.purchase_order_id.payment_mode_id.id
  +            or self.purchase_id.payment_mode_id.id
  +        )
  +        new_bank = (
  +            self.purchase_vendor_bill_id.purchase_order_id.supplier_partner_bank_id.id
  +            or self.purchase_id.supplier_partner_bank_id.id
  +        )
  +
           res = super()._onchange_purchase_auto_complete() or {}
           if self.payment_mode_id and new_mode and self.payment_mode_id.id != new_mode:
               res["warning"] = {
  
verification_info: {"golden_diff": "diff --git a/account_payment_purchase/models/account_invoice.py b/account_payment_purchase/models/account_invoice.py\n--- a/account_payment_purchase/models/account_invoice.py\n+++ b/account_payment_purchase/models/account_invoice.py\n@@ -10,8 +10,16 @@\n \n     @api.onchange(\"purchase_vendor_bill_id\", \"purchase_id\")\n     def _onchange_purchase_auto_complete(self):\n-        new_mode = self.purchase_id.payment_mode_id.id or False\n-        new_bank = self.purchase_id.supplier_partner_bank_id.id or False\n+\n+        new_mode = (\n+            self.purchase_vendor_bill_id.purchase_order_id.payment_mode_id.id\n+            or self.purchase_id.payment_mode_id.id\n+        )\n+        new_bank = (\n+            self.purchase_vendor_bill_id.purchase_order_id.supplier_partner_bank_id.id\n+            or self.purchase_id.supplier_partner_bank_id.id\n+        )\n+\n         res = super()._onchange_purchase_auto_complete() or {}\n         if self.payment_mode_id and new_mode and self.payment_mode_id.id != new_mode:\n             res[\"warning\"] = {\n", "issue": "[14.0] account_payment_purchase: changing many2one resets payment_mode\nHi,\r\nWe've seen that when the field purchase_vendor_bill_id is changed and a purchase is selected from it, the payment_mode_id is always reseted because it is using the reference purchase_id.\r\n`new_mode = self.purchase_id.payment_mode_id.id or False`\r\nWe've made this change, and it seems to work as it should.\r\n`new_mode = self.purchase_vendor_bill_id.purchase_order_id.payment_mode_id.id or False`\r\nThe same goes for the partner_bank_id field.\r\n@MiquelRForgeFlow \n", "before_files": [{"content": "# Copyright 2016 Akretion (<http://www.akretion.com>).\n# Copyright 2017 Tecnativa - Vicent Cubells.\n# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).\n\nfrom odoo import _, api, models\n\n\nclass AccountMove(models.Model):\n    _inherit = \"account.move\"\n\n    @api.onchange(\"purchase_vendor_bill_id\", \"purchase_id\")\n    def _onchange_purchase_auto_complete(self):\n        new_mode = self.purchase_id.payment_mode_id.id or False\n        new_bank = self.purchase_id.supplier_partner_bank_id.id or False\n        res = super()._onchange_purchase_auto_complete() or {}\n        if self.payment_mode_id and new_mode and self.payment_mode_id.id != new_mode:\n            res[\"warning\"] = {\n                \"title\": _(\"Warning\"),\n                \"message\": _(\"Selected purchase order have different payment mode.\"),\n            }\n            return res\n        self.payment_mode_id = new_mode\n        if self.partner_bank_id and new_bank and self.partner_bank_id.id != new_bank:\n            res[\"warning\"] = {\n                \"title\": _(\"Warning\"),\n                \"message\": _(\"Selected purchase order have different supplier bank.\"),\n            }\n            return res\n        self.partner_bank_id = new_bank\n        return res\n", "path": "account_payment_purchase/models/account_invoice.py"}]}