Merge pull request 'refactor odoo company type handling' (#143) from odoo-company-check into main
All checks were successful
Build and Deploy Staging / build (push) Successful in 1m1s
Build and Deploy Antora Docs / build (push) Successful in 59s
Tests / test (push) Successful in 24s
Build and Deploy Staging / deploy (push) Successful in 10s
Build and Deploy Antora Docs / deploy (push) Successful in 6s

Reviewed-on: #143
Reviewed-by: Tobias Kunze <r@rixx.de>
This commit is contained in:
Tobias Brunner 2025-07-07 12:11:29 +00:00
commit 24cb249e9e
4 changed files with 17 additions and 17 deletions

View file

@ -17,9 +17,9 @@ Search is done this way:
When choosing to add a new billing address, two new records are created in the Odoo `res.partner` model:
* A record with the field `company_type = company`
* A record with the field `is_company = False`
* A record with the following field configuration:
** `company_type = person`
** `is_company = False`
** `type = invoice`
** `parent_id = company_id`

View file

@ -147,8 +147,8 @@ class BillingEntity(ServalaModelMixin, models.Model):
)
# Odoo IDs are nullable for creation, should never be null in practice
# The company ID points at a record of type res.partner with company_type=company
# The invoice ID points at a record of type res.partner with company_type=person,
# The company ID points at a record of type res.partner with is_company=True
# The invoice ID points at a record of type res.partner with is_company=False,
# type=invoice, parent_id=company_id (the invoice address).
odoo_company_id = models.IntegerField(null=True)
odoo_invoice_id = models.IntegerField(null=True)
@ -166,8 +166,8 @@ class BillingEntity(ServalaModelMixin, models.Model):
"""
Creates a BillingEntity and corresponding Odoo records.
This method creates a `res.partner` record in Odoo with `company_type='company'`
for the main company, and another `res.partner` record with `company_type='person'`
This method creates a `res.partner` record in Odoo with `is_company=True`
for the main company, and another `res.partner` record with `is_company=False`
and `type='invoice'` (linked via `parent_id` to the first record) for the
invoice address. The IDs of these Odoo records are stored in the BillingEntity.
@ -187,14 +187,14 @@ class BillingEntity(ServalaModelMixin, models.Model):
instance = cls.objects.create(name=name)
company_payload = {
"name": odoo_data.get("company_name", name),
"company_type": "company",
"is_company": True,
}
company_id = CLIENT.execute("res.partner", "create", [company_payload])
instance.odoo_company_id = company_id
invoice_address_payload = {
"name": name,
"company_type": "person",
"is_company": False,
"type": "invoice",
"parent_id": company_id,
}
@ -249,10 +249,10 @@ class BillingEntity(ServalaModelMixin, models.Model):
"invoice_address": None,
}
company_fields = ["name", "company_type"]
company_fields = ["name", "is_company"]
invoice_address_fields = [
"name",
"company_type",
"is_company",
"type",
"parent_id",
"street",

View file

@ -84,7 +84,7 @@ class User(ServalaModelMixin, PermissionsMixin, AbstractBaseUser):
result = odoo.CLIENT.search_read(
model="res.partner",
domain=[
("company_type", "=", "person"),
("is_company", "=", False),
("type", "=", "contact"),
("email", "ilike", self.email),
("parent_id", "=", organization.billing_entity.odoo_company_id),
@ -107,7 +107,7 @@ class User(ServalaModelMixin, PermissionsMixin, AbstractBaseUser):
partner_data = {
"name": f"{self.first_name} {self.last_name}".strip() or self.email,
"email": self.email,
"company_type": "person",
"is_company": False,
"type": "contact",
"parent_id": organization.billing_entity.odoo_company_id,
}

View file

@ -15,7 +15,7 @@ ADDRESS_FIELDS = [
"email",
"phone",
"vat",
"company_type",
"is_company",
"type",
"parent_id",
]
@ -118,8 +118,8 @@ def get_odoo_countries():
def get_odoo_access_conditions(user):
# Were building our conditions in order:
# - in exceptions, users may be using a billing accounts email
# We're building our conditions in order:
# - in exceptions, users may be using a billing account's email
# - if the user is an admin or owner of a Servala organization
# - if the user is associated with an odoo user, return all billing
# addresses / organizations created by the user
@ -153,7 +153,7 @@ def get_odoo_access_conditions(user):
odoo_contacts = CLIENT.search_read(
model="res.partner",
domain=[
("company_type", "=", "person"),
("is_company", "=", False),
("type", "=", "contact"),
("email", "ilike", email),
],
@ -186,7 +186,7 @@ def get_invoice_addresses(user):
or_conditions = get_odoo_access_conditions(user)
domain = [
("company_type", "=", "person"),
("is_company", "=", False),
("type", "=", "invoice"),
] + or_conditions