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: 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: * A record with the following field configuration:
** `company_type = person` ** `is_company = False`
** `type = invoice` ** `type = invoice`
** `parent_id = company_id` ** `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 # 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 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 company_type=person, # The invoice ID points at a record of type res.partner with is_company=False,
# type=invoice, parent_id=company_id (the invoice address). # type=invoice, parent_id=company_id (the invoice address).
odoo_company_id = models.IntegerField(null=True) odoo_company_id = models.IntegerField(null=True)
odoo_invoice_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. Creates a BillingEntity and corresponding Odoo records.
This method creates a `res.partner` record in Odoo with `company_type='company'` This method creates a `res.partner` record in Odoo with `is_company=True`
for the main company, and another `res.partner` record with `company_type='person'` 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 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. 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) instance = cls.objects.create(name=name)
company_payload = { company_payload = {
"name": odoo_data.get("company_name", name), "name": odoo_data.get("company_name", name),
"company_type": "company", "is_company": True,
} }
company_id = CLIENT.execute("res.partner", "create", [company_payload]) company_id = CLIENT.execute("res.partner", "create", [company_payload])
instance.odoo_company_id = company_id instance.odoo_company_id = company_id
invoice_address_payload = { invoice_address_payload = {
"name": name, "name": name,
"company_type": "person", "is_company": False,
"type": "invoice", "type": "invoice",
"parent_id": company_id, "parent_id": company_id,
} }
@ -249,10 +249,10 @@ class BillingEntity(ServalaModelMixin, models.Model):
"invoice_address": None, "invoice_address": None,
} }
company_fields = ["name", "company_type"] company_fields = ["name", "is_company"]
invoice_address_fields = [ invoice_address_fields = [
"name", "name",
"company_type", "is_company",
"type", "type",
"parent_id", "parent_id",
"street", "street",

View file

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

View file

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