res_partner.py
1.1 KB
from odoo import api, fields, models
import logging
log = logging.getLogger(__name__)
class ResPartner(models.Model):
_description = 'Location'
_inherit = 'res.partner'
is_location = fields.Boolean(index=True)
geom = fields.GeoPolygon(index=True)
def search(self, args, offset=0, limit=None, order=None, count=False):
# this could have a check for this add domain based on a context value
partner_id = self.env.user.partner_id
args.append(('parent_id', '=', partner_id.id))
return super(ResPartner, self). \
search(args, offset, limit, order, count)
@api.model_create_multi
def create(self, values):
for val in values:
is_location = val.get('is_location')
company_id = val.get('company_id')
parent_id = val.get('parent_id')
if is_location:
if not company_id and not parent_id:
partner_id = self.env.user.partner_id
val['parent_id'] = partner_id.id
return super(ResPartner, self).create(values)