Skip to content

Instantly share code, notes, and snippets.

@aliomattux
Created August 18, 2015 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliomattux/566d2e319fca94a1febf to your computer and use it in GitHub Desktop.
Save aliomattux/566d2e319fca94a1febf to your computer and use it in GitHub Desktop.
def get_sale_address(self, cr, uid, partner_id, type, context=None):
base_search = ('parent_id', '=', partner_id)
if type == 'invoice':
preferred = 'is_default_billing'
elif type == 'delivery':
preferred = 'is_default_shipping'
else:
preferred = False
if preferred:
preferred_ids = self.search(cr, uid, [(preferred, '=', True), ('type', '=', type), base_search])
if preferred_ids:
return preferred_ids[0]
address_ids = self.search(cr, uid, [('type', '=', type), base_search])
if address_ids:
return address_ids[0]
contact_ids = self.search(cr, uid, [('type', '=', 'contact'), base_search])
if not contact_ids:
return partner_id
return contact_ids[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment