You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1002 B

  1. # Copyright 2020 Tecnativa - Carlos Dauden
  2. # Copyright 2020 Tecnativa - Sergio Teruel
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  4. from odoo import fields, models
  5. class ResPartner(models.Model):
  6. _inherit = "res.partner"
  7. partner_delivery_id = fields.Many2one(
  8. comodel_name="res.partner",
  9. string="Shipping address",
  10. )
  11. partner_invoice_id = fields.Many2one(
  12. comodel_name="res.partner",
  13. string="Invoice address",
  14. )
  15. def get_address_default_type(self):
  16. return ["delivery", "invoice"]
  17. def address_get(self, adr_pref=None):
  18. res = super().address_get(adr_pref)
  19. default_address_type_list = self.get_address_default_type()
  20. for partner in self:
  21. for addr_type in default_address_type_list:
  22. default_address_id = partner["partner_{}_id".format(addr_type)]
  23. if default_address_id:
  24. res[addr_type] = default_address_id.id
  25. return res