Compare commits
2 commits
c7d079e9bf
...
b36c0233db
Author | SHA1 | Date | |
---|---|---|---|
b36c0233db | |||
9a46229e81 |
2 changed files with 25 additions and 7 deletions
|
@ -184,11 +184,28 @@ class BillingEntity(ServalaModelMixin, models.Model):
|
|||
return instance
|
||||
|
||||
@classmethod
|
||||
def create_from_id(cls, odoo_id):
|
||||
# TODO implement odoo creation from ID
|
||||
# instance = BillingEntity.objects.create(name=odoo_data.get("name"))
|
||||
# return instance
|
||||
pass
|
||||
@transaction.atomic
|
||||
def create_from_id(cls, name, odoo_id):
|
||||
parent_data = CLIENT.search_read(
|
||||
model="res.partner",
|
||||
domain=[["id", "=", odoo_id]],
|
||||
fields=["parent_id"],
|
||||
limit=1,
|
||||
)
|
||||
# Data validation: If the data is not as expected, we just return None,
|
||||
# rather than raising an exception, for now.
|
||||
if not parent_data:
|
||||
return
|
||||
if not (parent_info := parent_data[0].get("parent_id")):
|
||||
return
|
||||
if not isinstance(parent_info, (list, tuple)) or not len(parent_info) > 0:
|
||||
# parent_info is a tuple of the parent’s ID and name
|
||||
return
|
||||
|
||||
instance = cls.objects.create(
|
||||
name=name, odoo_invoice_id=odoo_id, odoo_company_id=parent_info[0]
|
||||
)
|
||||
return instance
|
||||
|
||||
@cached_property
|
||||
def odoo_data(self):
|
||||
|
|
|
@ -10,11 +10,12 @@ Servala is run using environment variables. Documentation:
|
|||
"""
|
||||
|
||||
import os
|
||||
import sentry_sdk
|
||||
from pathlib import Path
|
||||
|
||||
import sentry_sdk
|
||||
from django.contrib import messages
|
||||
from sentry_sdk.integrations.django import DjangoIntegration
|
||||
|
||||
from django.contrib import messages
|
||||
from servala.__about__ import __version__ as version
|
||||
|
||||
SERVALA_ENVIRONMENT = os.environ.get("SERVALA_ENVIRONMENT", "development")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue