account_move.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import models, fields, api
  4. from odoo.tools.sql import column_exists, create_column
  5. class AccountMove(models.Model):
  6. _inherit = 'account.move'
  7. preferred_payment_method_id = fields.Many2one(
  8. string="Preferred Payment Method",
  9. comodel_name='account.payment.method',
  10. compute='_compute_preferred_payment_method_idd',
  11. store=True,
  12. )
  13. def _auto_init(self):
  14. """ Create column for `preferred_payment_method_id` to avoid having it
  15. computed by the ORM on installation. Since `property_payment_method_id` is
  16. introduced in this module, there is no need for UPDATE
  17. """
  18. if not column_exists(self.env.cr, "account_move", "preferred_payment_method_id"):
  19. create_column(self.env.cr, "account_move", "preferred_payment_method_id", "int4")
  20. return super()._auto_init()
  21. @api.depends('partner_id')
  22. def _compute_preferred_payment_method_idd(self):
  23. for move in self:
  24. partner = move.partner_id
  25. # take the payment method corresponding to the move's company
  26. move.preferred_payment_method_id = partner.with_company(move.company_id).property_payment_method_id