Skip to content

Commit

Permalink
[UPD] delivery_deliverea: Get partner data info
Browse files Browse the repository at this point in the history
  • Loading branch information
dalonsofl committed Dec 4, 2024
1 parent fc20867 commit 6770613
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 27 deletions.
29 changes: 11 additions & 18 deletions delivery_deliverea/models/delivery_carrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,29 +266,22 @@ def _check_mandatory_fields(self, values, mandatory_list, object_id):
% {"field": ", ".join(errors), "object_id": object_id.name}
)

def _get_field_from_partner_or_parent_id(self, partner, field):
return partner[field] or partner.parent_id and partner.parent_id[field] or ""

def _get_deliverea_sender_info(self, partner, request_type):
country_id = self._get_field_from_partner_or_parent_id(partner, "country_id")
state_id = self._get_field_from_partner_or_parent_id(partner, "state_id")
country_id = partner.get("country_id", "")
state_id = partner.get("state", "")
values = {
"name": self._get_field_from_partner_or_parent_id(partner, "name"),
"name": partner.get("name", ""),
"address": " ".join(
[
self._get_field_from_partner_or_parent_id(partner, "street"),
self._get_field_from_partner_or_parent_id(partner, "street2"),
]
partner.get("street", "").split(","),
).strip(),
"city": self._get_field_from_partner_or_parent_id(partner, "city"),
"zipCode": self._get_field_from_partner_or_parent_id(partner, "zip"),
"city": partner.get("city", ""),
"zipCode": partner.get("zip", ""),
"countryCode": country_id.code if country_id else "",
"idNumber": self._get_field_from_partner_or_parent_id(partner, "vat"),
"stateCode": state_id.code if state_id else "",
"idNumber": partner.get("vat", ""),
"stateCode": state_id,
"observations": "",
"phone": self._get_field_from_partner_or_parent_id(partner, "phone")
or self._get_field_from_partner_or_parent_id(partner, "mobile"),
"email": self._get_field_from_partner_or_parent_id(partner, "email"),
"phone": partner.get("phone", "") or partner.get("mobile", ""),
"email": partner.get("email", ""),
}
self._check_mandatory_fields(
values,
Expand Down Expand Up @@ -393,7 +386,7 @@ def _prepare_deliverea_order(self, picking):
request_type = "to" if picking.picking_type_code == "outgoing" else "from"
payload = {
request_type: self._get_deliverea_sender_info(
picking.partner_id, request_type
picking._get_partner_data(), request_type
),
"carrierCode": service.carrier_code,
"serviceCode": service.code,
Expand Down
59 changes: 50 additions & 9 deletions delivery_deliverea/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ def deliverea_update_tracking_state(self, data):
)
picking_id.write(
{
"delivery_state": deliverea_state.delivery_state
if deliverea_state
else False,
"date_delivered": datetime.strftime(
datetime.now(), DEFAULT_SERVER_DATETIME_FORMAT
)
if deliverea_state
and deliverea_state.delivery_state == "customer_delivered"
else False,
"delivery_state": (
deliverea_state.delivery_state if deliverea_state else False
),
"date_delivered": (
datetime.strftime(
datetime.now(), DEFAULT_SERVER_DATETIME_FORMAT
)
if deliverea_state
and deliverea_state.delivery_state == "customer_delivered"
else False
),
"carrier_tracking_url": data.get("advancedTrackingUrl"),
"tracking_state": "[{}] {}".format(
data.get("trackingCode"), data.get("trackingDetails")
Expand All @@ -63,3 +65,42 @@ def deliverea_update_tracking_state(self, data):
),
}
)

def _get_partner_data(self):
partner = self.partner_id
return {
"name": partner.display_name,
} | self._partner_info(partner)

def _get_warehouse_data(self):
warehouse = self.location_id.warehouse_id
warehouse_partner = warehouse.partner_id
return {
"name": warehouse.display_name,
} | self._partner_info(warehouse_partner)

def _partner_info(self, partner):
return {
"street": (
"%s, %s" % (partner.street, partner.street2)
if partner.street2
else "%s" % (partner.street)
),
"zip": partner.zip,
"state": partner.state_id.code,
"city": partner.city,
"phone": partner.phone
or partner.parent_id
and partner.parent_id.phone
or "",
"mobile": partner.mobile
or partner.parent_id
and partner.parent_id.mobile
or "",
"email": partner.email
or partner.parent_id
and partner.parent_id.email
or "",
"country_obj": partner.country_id,
"vat": partner.vat or partner.parent_id and partner.parent_id.vat or "",
}

0 comments on commit 6770613

Please sign in to comment.