Implement user:odoo contact mapping
All checks were successful
Tests / test (push) Successful in 24s
All checks were successful
Tests / test (push) Successful in 24s
ref #60
This commit is contained in:
parent
22ff769b2c
commit
e18cafa813
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.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]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue