Billing Entity Management #66
1 changed files with 17 additions and 0 deletions
|
@ -120,13 +120,30 @@ def get_invoice_addresses(user):
|
||||||
addresses the user owns or is connected to from the Odoo API."""
|
addresses the user owns or is connected to from the Odoo API."""
|
||||||
# We’re building our conditions in order:
|
# We’re building our conditions in order:
|
||||||
# - in exceptions, users may be using a billing account’s 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 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
|
||||||
# - if the user is associated with an odoo contact, return all billing
|
# - if the user is associated with an odoo contact, return all billing
|
||||||
# addresses with the same parent_id
|
# addresses with the same parent_id
|
||||||
|
from servala.core.models.organization import (
|
||||||
|
OrganizationMembership,
|
||||||
|
OrganizationRole,
|
||||||
|
)
|
||||||
|
|
||||||
email = user.email
|
email = user.email
|
||||||
tobru marked this conversation as resolved
Outdated
|
|||||||
or_conditions = [("email", "ilike", email)]
|
or_conditions = [("email", "ilike", email)]
|
||||||
|
|
||||||
|
servala_invoice_ids = list(
|
||||||
|
OrganizationMembership.objects.filter(
|
||||||
|
user=user, role__in=[OrganizationRole.ADMIN, OrganizationRole.OWNER]
|
||||||
tobru marked this conversation as resolved
Outdated
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.
|
|||||||
|
)
|
||||||
|
.values_list("organization__billing_entity__odoo_invoice_id", flat=True)
|
||||||
|
.distinct()
|
||||||
|
)
|
||||||
|
servala_invoice_ids = [pk for pk in servala_invoice_ids if pk]
|
||||||
|
if servala_invoice_ids:
|
||||||
|
or_conditions.append(("id", "in", servala_invoice_ids))
|
||||||
|
|
||||||
odoo_users = CLIENT.search_read(
|
odoo_users = CLIENT.search_read(
|
||||||
model="res.users",
|
model="res.users",
|
||||||
domain=[("login", "=", email), ("active", "=", True)],
|
domain=[("login", "=", email), ("active", "=", True)],
|
||||||
|
|
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.