Implement user:odoo contact mapping
All checks were successful
Tests / test (push) Successful in 24s

ref #60
This commit is contained in:
Tobias Kunze 2025-05-26 13:07:32 +02:00
parent 22ff769b2c
commit e18cafa813

View file

@ -6,7 +6,8 @@ from django.contrib.auth.models import (
from django.db import models from django.db import models
from django.utils.translation import gettext_lazy as _ 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): class UserManager(BaseUserManager):
@ -73,3 +74,22 @@ class User(ServalaModelMixin, PermissionsMixin, AbstractBaseUser):
def normalize_username(self, username): def normalize_username(self, username):
return super().normalize_username(username).strip().lower() 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]