Billing Entity Management #66
1 changed files with 34 additions and 21 deletions
|
@ -91,26 +91,40 @@ CLIENT = OdooClient()
|
|||
def get_invoice_addresses(user):
|
||||
"""Used during organization creation: retrieves all invoice
|
||||
addresses the user owns or is connected to from the Odoo API."""
|
||||
or_conditions = [
|
||||
("email", "ilike", user.email),
|
||||
("child_ids.email", "ilike", user.email),
|
||||
]
|
||||
# We’re building our conditions in order:
|
||||
# - in exceptions, users may be using a billing account’s email
|
||||
# - if the user is associated with an odoo user, return all billing
|
||||
# addresses / organizations created by the user
|
||||
# - if the user is associated with an odoo contact, return all billing
|
||||
# addresses with the same parent_id
|
||||
or_conditions = [("email", "ilike", email)]
|
||||
|
||||
# Attempt to find the Odoo user ID and add condition for records created by this user
|
||||
try:
|
||||
odoo_users = odoo_request(
|
||||
model="res.users",
|
||||
method="search_read",
|
||||
domain=[("login", "=", user.email)],
|
||||
fields=["id"],
|
||||
limit=1, # Expecting at most one user
|
||||
)
|
||||
if odoo_users and (uid := odoo_users[0].get("id")):
|
||||
or_conditions.append(("create_uid", "=", uid))
|
||||
except Exception:
|
||||
pass
|
||||
email = user if isinstance(user, str) else user.email
|
||||
odoo_users = CLIENT.search_read(
|
||||
model="res.users",
|
||||
domain=[("login", "=", email)],
|
||||
fields=["id"],
|
||||
limit=1,
|
||||
)
|
||||
if odoo_users and (uid := odoo_users[0].get("id")):
|
||||
or_conditions.append(("create_uid", "=", uid))
|
||||
|
||||
odoo_contacts = CLIENT.search_read(
|
||||
model="res.partner",
|
||||
domain=[
|
||||
("company_type", "=", "person"),
|
||||
("type", "=", "contact"),
|
||||
("email", "ilike", email),
|
||||
],
|
||||
fields=["id", "parent_id"],
|
||||
)
|
||||
if odoo_contacts:
|
||||
for contact in odoo_contacts:
|
||||
or_conditions.append(("parent_id", "=", contact["parent_id"][0]))
|
||||
|
||||
if len(or_conditions) > 1:
|
||||
or_conditions = ["|"] * (len(or_conditions) - 1) + or_conditions
|
||||
|
||||
user_conditions = ["|"] * (len(or_conditions) - 1) + or_conditions
|
||||
# The domain requires the partner to be an invoice address, that is:
|
||||
# Of the company_type=person, and type=invoice.
|
||||
# If we were searching for an existing organization, we would also have to
|
||||
|
@ -118,12 +132,11 @@ def get_invoice_addresses(user):
|
|||
domain = [
|
||||
("company_type", "=", "person"),
|
||||
|
||||
("type", "=", "invoice"),
|
||||
] + user_conditions
|
||||
] + or_conditions
|
||||
|
||||
try:
|
||||
invoice_addresses = odoo_request(
|
||||
invoice_addresses = CLIENT.search_read(
|
||||
tobru
commented
A user in the Servala Portal which matches an internal user in Odoo should be able to see all invoice addresses, like they do when they log in to the Odoo backend. I figured out that the "Internal Users" filter in Odoo uses the domain A user in the Servala Portal which matches an internal user in Odoo should be able to see all invoice addresses, like they do when they log in to the Odoo backend. I figured out that the "Internal Users" filter in Odoo uses the domain `('share', '=', False)` ([L342](https://github.com/odoo/odoo/blob/16.0/odoo/addons/base/views/res_users_views.xml#L342)) so let's use the same to decide if the user can see all invoice addresses. There are also "Portal Users" in Odoo, they should not see all invoice addresses and behave like a normal Servala Portal user.
|
||||
model="res.partner",
|
||||
method="search_read",
|
||||
domain=domain,
|
||||
fields=ADDRESS_FIELDS,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue
Enhance the domain to include
('active','=',True)
to make sure the user is active in Odoo.