Billing Entity Management #66
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):
|
||||
|
|
|
@ -21,10 +21,11 @@ class OrganizationCreateView(AutoPermissionRequiredMixin, CreateView):
|
|||
def form_valid(self, form):
|
||||
billing_choice = form.cleaned_data.get("billing_processing_choice")
|
||||
billing_entity = None
|
||||
name = form.cleaned_data["name"]
|
||||
|
||||
if not billing_choice or billing_choice == "new":
|
||||
billing_entity = BillingEntity.create_from_data(
|
||||
form.cleaned_data["name"],
|
||||
name,
|
||||
{
|
||||
key: value
|
||||
for key, value in form.cleaned_data.items()
|
||||
|
@ -37,7 +38,7 @@ class OrganizationCreateView(AutoPermissionRequiredMixin, CreateView):
|
|||
).first()
|
||||
|
||||
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:
|
||||
form.add_error(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue