From 4f39fd243e2464e7170977aa045ad396704cf107 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sun, 6 Dec 2015 10:08:52 +0530 Subject: [PATCH] [fixes] recreate print format, shipping address on po for drop ship, validate update stock --- .../doctype/sales_invoice/sales_invoice.py | 7 +++++++ .../drop_shipping/drop_shipping.json | 17 ----------------- .../__init__.py | 0 .../drop_shipping_format.json | 18 ++++++++++++++++++ .../selling/doctype/sales_order/sales_order.py | 10 +++++++--- 5 files changed, 32 insertions(+), 20 deletions(-) delete mode 100644 erpnext/buying/print_format/drop_shipping/drop_shipping.json rename erpnext/buying/print_format/{drop_shipping => drop_shipping_format}/__init__.py (100%) create mode 100644 erpnext/buying/print_format/drop_shipping_format/drop_shipping_format.json diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 4b33f104f0..7ad50d50e5 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -64,6 +64,7 @@ class SalesInvoice(SellingController): self.validate_pos() if cint(self.update_stock): + self.validate_dropship_item() self.validate_item_code() self.validate_warehouse() self.update_current_stock() @@ -409,6 +410,12 @@ class SalesInvoice(SellingController): if self.c_form_applicable == 'Yes' and self.c_form_no: msgprint(_("Please remove this Invoice {0} from C-Form {1}") .format(self.name, self.c_form_no), raise_exception = 1) + + def validate_dropship_item(self): + for item in self.items: + if item.sales_order: + if frappe.db.get_value("Sales Order Item", item.so_detail, "delivered_by_supplier"): + frappe.throw(_("Could not update stock, invoice contains drop shipping item.")) def update_current_stock(self): for d in self.get('items'): diff --git a/erpnext/buying/print_format/drop_shipping/drop_shipping.json b/erpnext/buying/print_format/drop_shipping/drop_shipping.json deleted file mode 100644 index 0af9a2425c..0000000000 --- a/erpnext/buying/print_format/drop_shipping/drop_shipping.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "creation": "2015-10-20 16:46:39.382799", - "custom_format": 0, - "disabled": 0, - "doc_type": "Purchase Order", - "docstatus": 0, - "doctype": "Print Format", - "font": "Default", - "format_data": "[{\"fieldname\": \"print_heading_template\", \"fieldtype\": \"HTML\", \"options\": \"

Purchase Order

{{doc.name}}

\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"title\"}, {\"print_hide\": 0, \"fieldname\": \"supplier\"}, {\"print_hide\": 0, \"fieldname\": \"supplier_name\"}, {\"print_hide\": 0, \"fieldname\": \"address_display\"}, {\"print_hide\": 0, \"fieldname\": \"contact_display\"}, {\"print_hide\": 0, \"fieldname\": \"contact_mobile\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"transaction_date\"}, {\"print_hide\": 0, \"fieldname\": \"customer\"}, {\"print_hide\": 0, \"fieldname\": \"customer_name\"}, {\"print_hide\": 0, \"fieldname\": \"customer_address_display\"}, {\"print_hide\": 0, \"fieldname\": \"customer_contact_display\"}, {\"print_hide\": 0, \"fieldname\": \"customer_contact_mobile\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"item_code\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"300px\"}, {\"print_hide\": 0, \"fieldname\": \"image\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"qty\", \"print_width\": \"60px\"}, {\"print_hide\": 0, \"fieldname\": \"uom\", \"print_width\": \"100px\"}, {\"print_hide\": 0, \"fieldname\": \"discount_percentage\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"pricing_rule\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"supplier_quotation\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"supplier_quotation_item\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"items\"}, {\"print_hide\": 0, \"fieldname\": \"get_last_purchase_rate\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"total\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"category\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"add_deduct_tax\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"charge_type\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"row_id\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"included_in_print_rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"account_head\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"cost_center\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"300px\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"total\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"taxes\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"grand_total\"}, {\"print_hide\": 0, \"fieldname\": \"in_words\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"terms\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"customer_contact_person\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"recurring_print_format\"}]", - "modified": "2015-10-20 17:21:45.810640", - "modified_by": "saurabh@erpnext.com", - "name": "Drop Shipping", - "owner": "Administrator", - "print_format_builder": 1, - "print_format_type": "Server", - "standard": "No" -} \ No newline at end of file diff --git a/erpnext/buying/print_format/drop_shipping/__init__.py b/erpnext/buying/print_format/drop_shipping_format/__init__.py similarity index 100% rename from erpnext/buying/print_format/drop_shipping/__init__.py rename to erpnext/buying/print_format/drop_shipping_format/__init__.py diff --git a/erpnext/buying/print_format/drop_shipping_format/drop_shipping_format.json b/erpnext/buying/print_format/drop_shipping_format/drop_shipping_format.json new file mode 100644 index 0000000000..cd2e826a56 --- /dev/null +++ b/erpnext/buying/print_format/drop_shipping_format/drop_shipping_format.json @@ -0,0 +1,18 @@ +{ + "creation": "2015-12-04 13:11:16.992997", + "custom_format": 1, + "disabled": 0, + "doc_type": "Purchase Order", + "docstatus": 0, + "doctype": "Print Format", + "font": "Default", + "html": "
\n
\n\t\t

Purchase Order
\n\t {{doc.name}}\n

\n
\n
\n
\n
\n\t\t\t\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{{doc.supplier_name}}\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t{% if doc.address_display %}\n\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t{{doc.address_display}}\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t{%- endif -%}\n\t\t\t\t{% if doc.contact_display %}\n\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t{{doc.contact_display}}\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t{%- endif -%}\n\t\t\t\t{% if doc.contact_mobile %}\n\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t{{doc.contact_mobile}}\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t{%- endif -%}\n
\n \n
\n
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t{{doc.transaction_date}}\n\t\t\t\t
\n\t\t\t
\n
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t{{doc.customer_name}}\n\t\t\t\t
\n\t\t\t
\n\t\t\t{% if doc.customer_address_display %}\n\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{{doc.customer_address_display}}\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t{%- endif -%}\n\t\t\t{% if doc.customer_contact_display %}\n\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{{doc.customer_contact_display}}\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t{%- endif -%}\n\t\t\t{% if doc.customer_contact_mobile %}\n\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{{doc.customer_contact_mobile}}\n\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t{%- endif -%}\n
\n
\n\t\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t{%- for row in doc.items -%}\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t{%- endfor -%}\n\t\t\n\t
SrItem NameDescriptionQtyRateAmount
{{ row.idx }}\n\t\t\t\t\t{{ row.item_name }}\n\t\t\t\t\t{% if row.item_code != row.item_name -%}\n\t\t\t\t\t
Item Code: {{ row.item_code}}\n\t\t\t\t\t{%- endif %}\n\t\t\t\t
\n\t\t\t\t\t
{{ row.description }}
{{ row.qty }} {{ row.uom or row.stock_uom }}{{\n\t\t\t\t\trow.get_formatted(\"rate\", doc) }}{{\n\t\t\t\t\trow.get_formatted(\"amount\", doc) }}
\n
\n
\n
\n
\n
\n\t\t\t\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{{doc.total}}\n\t\t\t\t\t
\n\t\t\t\t
\n
\n\t\t\t\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{{doc.grand_total}}\n\t\t\t\t\t
\n\t\t\t\t
\n
\n\t\t\t\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t\t\t\t{{doc.in_words}}\n\t\t\t\t\t
\n\t\t\t\t
\n
\n
\n
", + "idx": 0, + "modified": "2015-12-04 13:47:55.157482", + "modified_by": "Administrator", + "name": "Drop Shipping Format", + "owner": "Administrator", + "print_format_builder": 0, + "print_format_type": "Server", + "standard": "Yes" +} \ No newline at end of file diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 66ca31e916..05cb50c521 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -531,8 +531,14 @@ def make_purchase_order_for_drop_shipment(source_name, for_supplier, target_doc= default_price_list = frappe.get_value("Supplier", for_supplier, "default_price_list") if default_price_list: target.buying_price_list = default_price_list + + if source.shipping_address_name: + target.customer_address = source.shipping_address_name + target.customer_address_display = source.shipping_address + else: + target.customer_address = source.customer_address + target.customer_address_display = source.address_display - target.delivered_by_supplier = 1 target.run_method("set_missing_values") target.run_method("calculate_taxes_and_totals") @@ -544,9 +550,7 @@ def make_purchase_order_for_drop_shipment(source_name, for_supplier, target_doc= "Sales Order": { "doctype": "Purchase Order", "field_map": { - "customer_address": "customer_address", "contact_person": "customer_contact_person", - "address_display": "customer_address_display", "contact_display": "customer_contact_display", "contact_mobile": "customer_contact_mobile", "contact_email": "customer_contact_email",