Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikas8600 committed Apr 14, 2023
1 parent c71c886 commit 7b5e733
Showing 1 changed file with 29 additions and 90 deletions.
119 changes: 29 additions & 90 deletions ecommerce_integrations/unicommerce/delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,99 +72,38 @@ def create_delivery_note(order, settings, so):
if (
not frappe.db.get_value("Delivery Note", {"shipment_id":order["code"]}, "name")
):

frappe.logger("log1").exception("++++++++++++++++++++++"+str(so.unicommerce_order_code))
# Get the sales invoice
if frappe.get_value("Sales Invoice", {"unicommerce_order_code":so.unicommerce_order_code}):
sales_invoice = frappe.get_doc("Sales Invoice", {"unicommerce_order_code":so.unicommerce_order_code})
# create a new delivery note
delivery_note = frappe.get_doc({
"doctype": "Delivery Note",
"customer": so.customer,
"unicommerce_order_no":order["saleOrderCode"],
"shipment_id":order["code"],
"status": "Completed"
})

# Create the delivery note
delivery_note = frappe.new_doc("Delivery Note")
delivery_note.update({
"customer": sales_invoice.customer,
"customer_address": sales_invoice.customer_address,
"shipping_address_name": sales_invoice.shipping_address_name,
"posting_date": sales_invoice.posting_date,
"items": []
# add items to the delivery note
for item in so.items:
delivery_note.append("items", {
"item_code": item.item_code,
"qty": item.qty,
"rate": item.rate,
"warehouse":item.warehouse,
"against_sales_order":so.name
})
# add texes to the delivery note
for item in so.taxes:
delivery_note.append("taxes",{
"charge_type": item.charge_type,
"account_head": item.account_head,
"tax_amount": item.tax_amount,
"description": item.description,
"item_wise_tax_detail": item.item_wise_tax_detail,
"dont_recompute_tax": item.dont_recompute_tax,
})

# Add items to the delivery note
for item in sales_invoice.items:
delivery_note.append("items", {
"item_code": item.item_code,
"item_name": item.item_name,
"description": item.description,
"qty": item.qty,
"uom": item.uom,
"rate": item.rate,
"amount": item.amount,
"stock_qty": item.qty,
"so_detail": item.name,
"so_detail_item": item.idx,
"warehouse":item.warehouse,
"against_sales_order":so.name
})
for item in sales_invoice.taxes:
delivery_note.append("taxes",{
"charge_type": item.charge_type,
"account_head": item.account_head,
"tax_amount": item.tax_amount,
"description": item.description,
"item_wise_tax_detail": item.item_wise_tax_detail,
"dont_recompute_tax": item.dont_recompute_tax,
})
# Save the delivery note
delivery_note.flags.ignore_permissions = True
delivery_note.flags.ignore_mandatory = True
delivery_note.unicommerce_order_no = order["saleOrderCode"]
delivery_note.shipment_id = order["code"]
delivery_note.status = "Completed"
delivery_note.insert()

# Submit the delivery note
delivery_note.submit()

# Update the sales invoice with the delivery note information
sales_invoice.delivery_note = delivery_note.name
sales_invoice.flags.ignore_permissions = True
sales_invoice.flags.ignore_mandatory = True
sales_invoice.save()


# create a new delivery note

# delivery_note = frappe.get_doc({
# "doctype": "Delivery Note",
# "customer": so.customer,
# "unicommerce_order_no":order["saleOrderCode"],
# "shipment_id":order["code"],
# "status": "Completed"
# })

# # add items to the delivery note
# for item in so.items:
# delivery_note.append("items", {
# "item_code": item.item_code,
# "qty": item.qty,
# "rate": item.rate,
# "warehouse":item.warehouse,
# "against_sales_order":so.name
# })
# # add texes to the delivery note
# for item in so.taxes:
# delivery_note.append("taxes",{
# "charge_type": item.charge_type,
# "account_head": item.account_head,
# "tax_amount": item.tax_amount,
# "description": item.description,
# "item_wise_tax_detail": item.item_wise_tax_detail,
# "dont_recompute_tax": item.dont_recompute_tax,
# })

# # save the delivery note
# delivery_note.insert()
# delivery_note.submit()
# save the delivery note
delivery_note.insert()
delivery_note.submit()

except Exception as e:
frappe.logger("log1").exception(e)
create_unicommerce_log(status="Error", exception=e, rollback=True)

0 comments on commit 7b5e733

Please sign in to comment.