parent
611172afdb
commit
7c4dcb7df4
1 changed files with 21 additions and 1 deletions
|
@ -6,7 +6,8 @@ from django.contrib.auth.models import (
|
|||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .mixins import ServalaModelMixin
|
||||
from servala.core import odoo
|
||||
from servala.core.models.mixins import ServalaModelMixin
|
||||
|
||||
|
||||
class UserManager(BaseUserManager):
|
||||
|
@ -73,3 +74,22 @@ class User(ServalaModelMixin, PermissionsMixin, AbstractBaseUser):
|
|||
|
||||
def normalize_username(self, username):
|
||||
return super().normalize_username(username).strip().lower()
|
||||
|
||||
def get_odoo_contact(self, organization):
|
||||
if (
|
||||
not organization.billing_entity
|
||||
or not organization.billing_entity.odoo_company_id
|
||||
):
|
||||
return
|
||||
result = odoo.CLIENT.search_read(
|
||||
model="res.partner",
|
||||
domain=[
|
||||
("company_type", "=", "person"),
|
||||
("type", "=", "contact"),
|
||||
("email", "ilike", self.email),
|
||||
("parent_id", "=", organization.billing_entity.odoo_company_id),
|
||||
],
|
||||
fields=odoo.ADDRESS_FIELDS,
|
||||
)
|
||||
if result:
|
||||
return result[0]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue