Created
August 18, 2015 00:35
-
-
Save aliomattux/566d2e319fca94a1febf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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