Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] sale_order_import_ubl_customer_free_ref: add customer_expected_delivery_* when creating order from import ubl #27

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,27 @@ def test_ubl_order_import(self):
),
"invoicing_partner": self.env.ref("sale_order_import_ubl.karlsson"),
"currency": self.env.ref("base.SEK"),
"customer_exp_delivery_start": "2010-02-10",
"customer_exp_delivery_end": "2010-02-25",
"order_line": {
0: {
"customer_exp_delivery_start": "2010-02-10",
"customer_exp_delivery_end": "2010-02-25",
},
1: {
"customer_exp_delivery_start": "2010-02-10",
"customer_exp_delivery_end": "2010-02-25",
},
},
},
"UBL-Order-2.0-Example.xml": {
"client_order_ref": "AEG012345",
"date_order": "2010-06-20",
"partner": self.env.ref("sale_order_import_ubl.fred_churchill"),
"shipping_partner": self.env.ref("sale_order_import_ubl.iyt"),
"currency": self.env.ref("base.GBP"),
"customer_exp_delivery_start": "2005-06-29",
"customer_exp_delivery_end": "2005-06-29",
},
}
for filename, res in tests.items():
Expand Down Expand Up @@ -62,3 +76,34 @@ def test_ubl_order_import(self):
self.assertEqual(date_order[:10], res["date_order"])
if res.get("shipping_partner"):
self.assertEqual(so.partner_shipping_id, res["shipping_partner"])
if res.get("customer_exp_delivery_start"):
customer_exp_delivery_start = so.customer_exp_delivery_start.strftime(
"%Y-%m-%d"
)
self.assertEqual(
customer_exp_delivery_start, res["customer_exp_delivery_start"]
)
if res.get("customer_exp_delivery_end"):
customer_exp_delivery_end = so.customer_exp_delivery_end.strftime(
"%Y-%m-%d"
)
self.assertEqual(
customer_exp_delivery_end, res["customer_exp_delivery_end"]
)
if res.get("order_line"):
for key, val in res["order_line"].items():
if val.get("customer_exp_delivery_start"):
customer_exp_delivery_start = so.order_line[
key
].customer_exp_delivery_start.strftime("%Y-%m-%d")
self.assertEqual(
customer_exp_delivery_start,
val["customer_exp_delivery_start"],
)
if val.get("customer_exp_delivery_end"):
customer_exp_delivery_end = so.order_line[
key
].customer_exp_delivery_end.strftime("%Y-%m-%d")
self.assertEqual(
customer_exp_delivery_end, val["customer_exp_delivery_end"]
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def _prepare_order(self, parsed_order, price_source):
res = super()._prepare_order(parsed_order, price_source)
res["customer_order_number"] = parsed_order.get("order_ref")
res["customer_order_free_ref"] = parsed_order.get("customer_reference", "")
res["customer_exp_delivery_start"] = parsed_order.get(
"customer_exp_delivery_start"
)
res["customer_exp_delivery_end"] = parsed_order.get("customer_exp_delivery_end")
# Removed because will be computed
res.pop("client_order_ref")
return res
Expand All @@ -50,4 +54,34 @@ def parse_ubl_sale_order(self, xml_root):
if customer_ref_xpath:
ref = customer_ref_xpath[0].text
res["customer_reference"] = ref
requested_delivery_xpath = xml_root.xpath(
"/%s/cac:Delivery/cac:RequestedDeliveryPeriod" % root_name, namespaces=ns
)
if requested_delivery_xpath:
if requested_delivery_xpath[0].xpath("cbc:StartDate", namespaces=ns):
res["customer_exp_delivery_start"] = (
requested_delivery_xpath[0]
.xpath("cbc:StartDate", namespaces=ns)[0]
.text
)
if requested_delivery_xpath[0].xpath("cbc:EndDate", namespaces=ns):
res["customer_exp_delivery_end"] = (
requested_delivery_xpath[0]
.xpath("cbc:EndDate", namespaces=ns)[0]
.text
)
return res

def parse_ubl_sale_order_line(self, line, ns):
vals = super().parse_ubl_sale_order_line(line, ns)
line_item = line.xpath("cac:LineItem", namespaces=ns)[0]
expected_delivery_date = line_item.xpath(
"cac:Delivery/cac:RequestedDeliveryPeriod", namespaces=ns
)
if expected_delivery_date:
start_date = expected_delivery_date[0].xpath("cbc:StartDate", namespaces=ns)
end_date = expected_delivery_date[0].xpath("cbc:EndDate", namespaces=ns)
if start_date and end_date:
vals["customer_exp_delivery_start"] = start_date[0].text
vals["customer_exp_delivery_end"] = end_date[0].text
return vals
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ responses
# Python Dependencies
PyYAML
xmlunittest

odoo14-addon-sale_order_customer_free_ref @ git+https://github.com/thienvh332/edi@refs/pull/26/head#subdirectory=setup/sale_order_customer_free_ref
Loading