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

fix: create DN based on fulfilment #62

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
35 changes: 25 additions & 10 deletions shopify_integration/fulfilments.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
if TYPE_CHECKING:
from erpnext.selling.doctype.sales_order.sales_order import SalesOrder
from erpnext.stock.doctype.delivery_note.delivery_note import DeliveryNote
from erpnext.stock.doctype.delivery_note_item.delivery_note_item import DeliveryNoteItem
from shopify import Fulfillment, LineItem, Order
from shopify_integration.shopify_integration.doctype.shopify_settings.shopify_settings import ShopifySettings

Expand Down Expand Up @@ -110,7 +109,7 @@ def create_delivery_notes(
{"docstatus": 1, "shopify_fulfillment_id": fulfillment.id}, "name")

if not existing_delivery:
dn: "DeliveryNote" = make_delivery_note(sales_order.name)
dn: "DeliveryNote" = make_delivery_note(source_name=sales_order.name, skip_item_mapping=True)
dn.update({
"shopify_settings": shopify_settings.name,
"shopify_order_id": shopify_order.id,
Expand All @@ -122,9 +121,9 @@ def create_delivery_notes(
"naming_series": shopify_settings.delivery_note_series or "DN-Shopify-",
})

update_fulfillment_items(dn.items, fulfillment.attributes.get("line_items"))

dn.flags.ignore_mandatory = True
dn_items = update_fulfillment_items(sales_order, fulfillment.attributes.get("line_items"))
dn.items = dn_items
dn.save()
dn.submit()
frappe.db.commit()
Expand All @@ -134,12 +133,28 @@ def create_delivery_notes(


def update_fulfillment_items(
dn_items: List["DeliveryNoteItem"],
fulfillment_items: List["LineItem"]
so: List["SalesOrder"],
fulfillment_items: List["LineItem"],
):
for dn_item in dn_items:
dn_items= []
for so_item in so.items:
# TODO: figure out a better way to add items without setting valuation rate to zero
dn_item.allow_zero_valuation_rate = True
for item in fulfillment_items:
if get_item_code(item) == dn_item.item_code:
dn_item.qty = item.attributes.get("quantity")
if get_item_code(item) == so_item.item_code:
dn_item = frappe.new_doc("Delivery Note Item")
dn_item.update({
"allow_zero_valuation_rate": True, # is it necesarry now? #L151
"item_code": so_item.item_code,
"item_name": so_item.item_name,
"description": so_item.description,
"qty": item.attributes.get("quantity"),
"rate": so_item.rate,
"against_sales_order": so.name,
"shopify_order_item_id": item.attributes.get("id"),
"parenttype": "Delivery Note",
"parentfield": "items",
})
dn_items.append(dn_item)

return dn_items

Loading