Billing Entity Management #66
2 changed files with 25 additions and 7 deletions
|
@ -184,11 +184,28 @@ class BillingEntity(ServalaModelMixin, models.Model):
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_id(cls, odoo_id):
|
@transaction.atomic
|
||||||
# TODO implement odoo creation from ID
|
def create_from_id(cls, name, odoo_id):
|
||||||
# instance = BillingEntity.objects.create(name=odoo_data.get("name"))
|
parent_data = CLIENT.search_read(
|
||||||
# return instance
|
model="res.partner",
|
||||||
pass
|
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
|
@cached_property
|
||||||
def odoo_data(self):
|
def odoo_data(self):
|
||||||
|
|
|
@ -21,10 +21,11 @@ class OrganizationCreateView(AutoPermissionRequiredMixin, CreateView):
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
billing_choice = form.cleaned_data.get("billing_processing_choice")
|
billing_choice = form.cleaned_data.get("billing_processing_choice")
|
||||||
billing_entity = None
|
billing_entity = None
|
||||||
|
name = form.cleaned_data["name"]
|
||||||
|
|
||||||
if not billing_choice or billing_choice == "new":
|
if not billing_choice or billing_choice == "new":
|
||||||
billing_entity = BillingEntity.create_from_data(
|
billing_entity = BillingEntity.create_from_data(
|
||||||
form.cleaned_data["name"],
|
name,
|
||||||
{
|
{
|
||||||
key: value
|
key: value
|
||||||
for key, value in form.cleaned_data.items()
|
for key, value in form.cleaned_data.items()
|
||||||
|
@ -37,7 +38,7 @@ class OrganizationCreateView(AutoPermissionRequiredMixin, CreateView):
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if not billing_entity:
|
if not billing_entity:
|
||||||
billing_entity = BillingEntity.create_from_id(odoo_id)
|
billing_entity = BillingEntity.create_from_id(name, odoo_id)
|
||||||
|
|
||||||
if not billing_entity:
|
if not billing_entity:
|
||||||
form.add_error(
|
form.add_error(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue