From 01d6df45d00d5b09c46b5fbf689645e2e65a9349 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Fri, 15 Jul 2022 11:17:41 +0530 Subject: [PATCH 01/14] fix(india): e-way bill json for unregistered gst category --- erpnext/regional/india/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index 160eebca6e7..1f5212857aa 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -580,7 +580,7 @@ def get_ewb_data(dt, dn): if dt == "Delivery Note": data.subSupplyType = 1 - elif doc.gst_category in ["Registered Regular", "SEZ"]: + elif doc.gst_category in ["Unregistered", "Registered Regular", "SEZ"]: data.subSupplyType = 1 elif doc.gst_category in ["Overseas", "Deemed Export"]: data.subSupplyType = 3 From 1d69ce1932938ce98e8700a01e7403f747e9bf3d Mon Sep 17 00:00:00 2001 From: Maharshi Patel Date: Thu, 21 Jul 2022 13:27:30 +0530 Subject: [PATCH 02/14] fix: (india) add overseas in HSN wise report SQL query had WHERE `tabSales Taxes and Charges`.parent = `tabSales Invoice`.name. However, In overseas, there is no `tabSales Taxes and Charges` so I changed the query to use a combination of INNER JOIN and LEFT JOIN to fetch all entries. --- .../hsn_wise_summary_of_outward_supplies.py | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/erpnext/regional/report/hsn_wise_summary_of_outward_supplies/hsn_wise_summary_of_outward_supplies.py b/erpnext/regional/report/hsn_wise_summary_of_outward_supplies/hsn_wise_summary_of_outward_supplies.py index 84721c03081..f171b6e9cbe 100644 --- a/erpnext/regional/report/hsn_wise_summary_of_outward_supplies/hsn_wise_summary_of_outward_supplies.py +++ b/erpnext/regional/report/hsn_wise_summary_of_outward_supplies/hsn_wise_summary_of_outward_supplies.py @@ -33,7 +33,7 @@ def _execute(filters=None): added_item = [] for d in item_list: if (d.parent, d.item_code) not in added_item: - row = [d.gst_hsn_code, d.description, d.stock_uom, d.stock_qty, d.tax_rate] + row = [d.gst_hsn_code, d.description, d.stock_uom, d.stock_qty, d.tax_rate or 0] total_tax = 0 for tax in tax_columns: item_tax = itemised_tax.get((d.parent, d.item_code), {}).get(tax, {}) @@ -100,31 +100,51 @@ def get_items(filters): items = frappe.db.sql( """ - select + SELECT `tabSales Invoice Item`.gst_hsn_code, `tabSales Invoice Item`.stock_uom, - sum(`tabSales Invoice Item`.stock_qty) as stock_qty, - sum(`tabSales Invoice Item`.base_net_amount) as base_net_amount, - sum(`tabSales Invoice Item`.base_price_list_rate) as base_price_list_rate, + sum( + `tabSales Invoice Item`.stock_qty + ) as stock_qty, + sum( + `tabSales Invoice Item`.base_net_amount + ) as base_net_amount, + sum( + `tabSales Invoice Item`.base_price_list_rate + ) as base_price_list_rate, + `tabSales Invoice Item`.parent, `tabSales Invoice Item`.item_code, `tabGST HSN Code`.description, - json_extract(`tabSales Taxes and Charges`.item_wise_tax_detail, - concat('$."' , `tabSales Invoice Item`.item_code, '"[0]')) * count(distinct `tabSales Taxes and Charges`.name) as tax_rate - from - `tabSales Invoice`, - `tabSales Invoice Item`, - `tabGST HSN Code`, - `tabSales Taxes and Charges` - where - `tabSales Invoice`.name = `tabSales Invoice Item`.parent - and `tabSales Taxes and Charges`.parent = `tabSales Invoice`.name - and `tabSales Invoice`.docstatus = 1 - and `tabSales Invoice Item`.gst_hsn_code is not NULL - and `tabSales Invoice Item`.gst_hsn_code = `tabGST HSN Code`.name %s %s - group by + json_extract( + `tabSales Taxes and Charges`.item_wise_tax_detail, + concat( + '$."', `tabSales Invoice Item`.item_code, + '"[0]' + ) + ) * count( + distinct `tabSales Taxes and Charges`.name + ) as tax_rate + FROM + `tabSales Invoice` + INNER JOIN + `tabSales Invoice Item` ON `tabSales Invoice`.name = `tabSales Invoice Item`.parent + INNER JOIN + `tabGST HSN Code` ON `tabSales Invoice Item`.gst_hsn_code = `tabGST HSN Code`.name % s % s + LEFT JOIN + `tabSales Taxes and Charges` ON `tabSales Taxes and Charges`.parent = `tabSales Invoice`.name + WHERE + `tabSales Invoice`.docstatus = 1 + AND + `tabSales Invoice Item`.gst_hsn_code is not NULL + GROUP BY `tabSales Invoice Item`.parent, - `tabSales Invoice Item`.item_code + `tabSales Invoice Item`.item_code, + `tabSales Invoice Item`.gst_hsn_code, + `tabSales Invoice Item`.uom + ORDER BY + `tabSales Invoice Item`.gst_hsn_code, + `tabSales Invoice Item`.uom """ % (conditions, match_conditions), filters, From 529a47bc88ec82ca39a93ad7386184c981104861 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 22 Jul 2022 11:17:59 +0530 Subject: [PATCH 03/14] fix: rounding errors while closing pos (backport #31654) (#31658) --- .../pos_invoice_merge_log/pos_invoice_merge_log.py | 5 ++++- erpnext/accounts/doctype/pos_profile/pos_profile.json | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index d3a81fe61dc..5003a1d6a81 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -9,7 +9,7 @@ from frappe import _ from frappe.core.page.background_jobs.background_jobs import get_info from frappe.model.document import Document from frappe.model.mapper import map_child_doc, map_doc -from frappe.utils import flt, getdate, nowdate +from frappe.utils import cint, flt, getdate, nowdate from frappe.utils.background_jobs import enqueue from frappe.utils.scheduler import is_scheduler_inactive @@ -219,6 +219,9 @@ class POSInvoiceMergeLog(Document): invoice.taxes_and_charges = None invoice.ignore_pricing_rule = 1 invoice.customer = self.customer + invoice.disable_rounded_total = cint( + frappe.db.get_value("POS Profile", invoice.pos_profile, "disable_rounded_total") + ) if self.merge_invoices_based_on == "Customer Group": invoice.flags.ignore_pos_profile = True diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json index 11646a6517d..d5f7ee4f217 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.json +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json @@ -44,6 +44,7 @@ "write_off_account", "write_off_cost_center", "account_for_change_amount", + "disable_rounded_total", "column_break_23", "income_account", "expense_account", @@ -358,6 +359,13 @@ "fieldname": "validate_stock_on_save", "fieldtype": "Check", "label": "Validate Stock on Save" + }, + { + "default": "0", + "description": "If enabled, the consolidated invoices will have rounded total disabled", + "fieldname": "disable_rounded_total", + "fieldtype": "Check", + "label": "Disable Rounded Total" } ], "icon": "icon-cog", @@ -385,7 +393,7 @@ "link_fieldname": "pos_profile" } ], - "modified": "2022-03-21 13:29:28.480533", + "modified": "2022-07-21 11:16:46.911173", "modified_by": "Administrator", "module": "Accounts", "name": "POS Profile", From bc7cfe69190f53dd4203717373dc6a51c61b0481 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 26 Jul 2022 12:35:50 +0530 Subject: [PATCH 04/14] fix: do not update component amount for timesheet components (#31696) * fix: do not update component amount for timesheet components * fix: warn the user about overwriting timesheet component amount --- erpnext/non_profit/doctype/member/member.js | 2 +- .../payroll/doctype/salary_slip/salary_slip.py | 7 +++++++ .../doctype/salary_structure/salary_structure.py | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/erpnext/non_profit/doctype/member/member.js b/erpnext/non_profit/doctype/member/member.js index 6462939ead2..f72d4d958b9 100644 --- a/erpnext/non_profit/doctype/member/member.js +++ b/erpnext/non_profit/doctype/member/member.js @@ -27,7 +27,7 @@ frappe.ui.form.on('Member', { frappe.set_route('query-report', 'General Ledger', {party_type: 'Member', party: frm.doc.name}); } }); - + if (frm.doc.customer) { frm.add_custom_button(__('Accounts Receivable'), function() { frappe.set_route('query-report', 'Accounts Receivable', {customer: frm.doc.customer}); diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index f652125337b..dedc880da60 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -623,7 +623,14 @@ class SalarySlip(TransactionBase): def add_structure_components(self, component_type): data = self.get_data_for_eval() + timesheet_component = frappe.db.get_value( + "Salary Structure", self.salary_structure, "salary_component" + ) + for struct_row in self._salary_structure_doc.get(component_type): + if self.salary_slip_based_on_timesheet and struct_row.salary_component == timesheet_component: + continue + amount = self.eval_condition_and_formula(struct_row, data) if amount is not None and struct_row.statistical_component == 0: self.update_component_row(struct_row, amount, component_type, data=data) diff --git a/erpnext/payroll/doctype/salary_structure/salary_structure.py b/erpnext/payroll/doctype/salary_structure/salary_structure.py index bebf0303798..caf9d9bb7c8 100644 --- a/erpnext/payroll/doctype/salary_structure/salary_structure.py +++ b/erpnext/payroll/doctype/salary_structure/salary_structure.py @@ -20,6 +20,7 @@ class SalaryStructure(Document): self.validate_max_benefits_with_flexi() self.validate_component_based_on_tax_slab() self.validate_payment_days_based_dependent_component() + self.validate_timesheet_component() def set_missing_values(self): overwritten_fields = [ @@ -89,6 +90,21 @@ class SalaryStructure(Document): return abbr + def validate_timesheet_component(self): + if not self.salary_slip_based_on_timesheet: + return + + for component in self.earnings: + if component.salary_component == self.salary_component: + frappe.msgprint( + _( + "Row #{0}: Timesheet amount will overwrite the Earning component amount for the Salary Component {1}" + ).format(self.idx, frappe.bold(self.salary_component)), + title=_("Warning"), + indicator="orange", + ) + break + def strip_condition_and_formula_fields(self): # remove whitespaces from condition and formula fields for row in self.earnings: From b97d30aad098d87e6c95ff1dab37360ac574e17a Mon Sep 17 00:00:00 2001 From: Maharshi Patel Date: Tue, 26 Jul 2022 12:57:47 +0530 Subject: [PATCH 05/14] fix: (india) (e-invoice) margin & internal company transfer When the item price is more than the price list rate ( margin added ) discount value becomes negative. The previous attempt to solve this was to convert discount to absolute value. However, that gives incorrect unit price and discount value. To solve this, I have made changes to report net rates in cases where the margin is added or is an internal company transfer. --- erpnext/regional/india/e_invoice/utils.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index bf304bc10dc..8e652bbb163 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -265,6 +265,10 @@ def get_overseas_address_details(address_name): def get_item_list(invoice): item_list = [] + hide_discount_in_einvoice = cint( + frappe.db.get_single_value("E Invoice Settings", "dont_show_discounts_in_e_invoice") + ) + for d in invoice.items: einvoice_item_schema = read_json("einv_item_template") item = frappe._dict({}) @@ -276,17 +280,12 @@ def get_item_list(invoice): item.qty = abs(item.qty) item_qty = item.qty - item.discount_amount = abs(item.discount_amount) item.taxable_value = abs(item.taxable_value) if invoice.get("is_return") or invoice.get("is_debit_note"): item_qty = item_qty or 1 - hide_discount_in_einvoice = cint( - frappe.db.get_single_value("E Invoice Settings", "dont_show_discounts_in_e_invoice") - ) - - if hide_discount_in_einvoice: + if hide_discount_in_einvoice or invoice.is_internal_customer or (item.discount_amount <= 0): item.unit_rate = item.taxable_value / item_qty item.gross_amount = item.taxable_value item.discount_amount = 0 From 8a6432ec3f4bf63c39d1f687f618cec2360ebccf Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 26 Jul 2022 13:43:36 +0530 Subject: [PATCH 06/14] fix: hero image not loading in portal homepage (#31699) --- erpnext/templates/pages/home.css | 1 - erpnext/templates/pages/home.html | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/erpnext/templates/pages/home.css b/erpnext/templates/pages/home.css index 785d8059ba0..f2661491ce2 100644 --- a/erpnext/templates/pages/home.css +++ b/erpnext/templates/pages/home.css @@ -1,7 +1,6 @@ /* csslint ignore:start */ {% if homepage.hero_image %} .hero-image { - background-image: url("{{ homepage.hero_image }}"); background-size: cover; padding: 10rem 0; } diff --git a/erpnext/templates/pages/home.html b/erpnext/templates/pages/home.html index 9a61eabaf8c..4c69b8388de 100644 --- a/erpnext/templates/pages/home.html +++ b/erpnext/templates/pages/home.html @@ -5,7 +5,11 @@ {% block content %}
{% if homepage.hero_section_based_on == 'Default' %} -
+

{{ homepage.tag_line }}

{{ homepage.tag_line }}

From a843e784e6f4ce60be8d5d5a39154dca3bad07e6 Mon Sep 17 00:00:00 2001 From: Maharshi Patel Date: Tue, 26 Jul 2022 17:40:59 +0530 Subject: [PATCH 07/14] fix: discount and test added only report net rate if discount is less than 0 and added test. --- .../sales_invoice/test_sales_invoice.py | 26 +++++++++++++++++++ erpnext/regional/india/e_invoice/utils.py | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 0a5172eaba6..2df095a41a0 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2712,6 +2712,19 @@ class TestSalesInvoice(unittest.TestCase): self.assertEqual(einvoice["ItemList"][2]["UnitPrice"], 20) self.assertEqual(einvoice["ItemList"][3]["UnitPrice"], 10) + si = get_sales_invoice_for_e_invoice() + si.apply_discount_on = "" + si.items[1].price_list_rate = 15 + si.items[1].discount_amount = -5 + si.items[1].rate = 20 + si.save() + + einvoice = make_einvoice(si) + validate_totals(einvoice) + + self.assertEqual(einvoice["ItemList"][1]["Discount"], 0) + self.assertEqual(einvoice["ItemList"][1]["UnitPrice"], 20) + def test_einvoice_without_discounts(self): from erpnext.regional.india.e_invoice.utils import make_einvoice, validate_totals @@ -2804,6 +2817,19 @@ class TestSalesInvoice(unittest.TestCase): self.assertEqual(einvoice["ItemList"][2]["UnitPrice"], 18) self.assertEqual(einvoice["ItemList"][3]["UnitPrice"], 5) + si = get_sales_invoice_for_e_invoice() + si.apply_discount_on = "" + si.items[1].price_list_rate = 15 + si.items[1].discount_amount = -5 + si.items[1].rate = 20 + si.save() + + einvoice = make_einvoice(si) + validate_totals(einvoice) + + self.assertEqual(einvoice["ItemList"][1]["Discount"], 0) + self.assertEqual(einvoice["ItemList"][1]["UnitPrice"], 20) + def test_item_tax_net_range(self): item = create_item("T Shirt") diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 8e652bbb163..9292fc1cfec 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -285,7 +285,7 @@ def get_item_list(invoice): if invoice.get("is_return") or invoice.get("is_debit_note"): item_qty = item_qty or 1 - if hide_discount_in_einvoice or invoice.is_internal_customer or (item.discount_amount <= 0): + if hide_discount_in_einvoice or invoice.is_internal_customer or item.discount_amount < 0: item.unit_rate = item.taxable_value / item_qty item.gross_amount = item.taxable_value item.discount_amount = 0 From 4f023757dee6545dadb1f4ba85d26c4b164dfa70 Mon Sep 17 00:00:00 2001 From: MohsinAli Date: Wed, 27 Jul 2022 11:50:15 +0530 Subject: [PATCH 08/14] fix: payment entry to student (#31708) Payment entry to student via Payment References(From Journal Entry) --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index d8ce89c59d2..b1976ebae65 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -305,7 +305,7 @@ class PaymentEntry(AccountsController): def validate_reference_documents(self): if self.party_type == "Student": - valid_reference_doctypes = "Fees" + valid_reference_doctypes = ("Fees", "Journal Entry") elif self.party_type == "Customer": valid_reference_doctypes = ("Sales Order", "Sales Invoice", "Journal Entry", "Dunning") elif self.party_type == "Supplier": From 32c1bb61de5e70cb8ca3d6bfc12eb11b17b96690 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 27 Jul 2022 12:44:26 +0530 Subject: [PATCH 09/14] fix: manually generated salary slips overwritten by structure amount (#31711) --- erpnext/payroll/doctype/salary_slip/salary_slip.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index dedc880da60..8034f01bc63 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -632,7 +632,11 @@ class SalarySlip(TransactionBase): continue amount = self.eval_condition_and_formula(struct_row, data) - if amount is not None and struct_row.statistical_component == 0: + if ( + amount + or (struct_row.amount_based_on_formula and amount is not None) + and struct_row.statistical_component == 0 + ): self.update_component_row(struct_row, amount, component_type, data=data) def get_data_for_eval(self): From b393c230bdc6fcd0939ef8cfa80a11167cad74c6 Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 27 Jun 2022 13:00:00 +0530 Subject: [PATCH 10/14] chore: Make `image` field obsolete in Website Item (redundant) - Delete Image field and set `website_image` as form's image field for uploads - Remove instances of `image` field access via Website Item - Item -> Web Item via Desk: Map Item's `image` to Web Item's `website_image` - Item -> Web Item via patch: `website_image` will be mapped with thumbnail - Remove magic that auto-sets `website_image` from `image` in Website Item (cherry picked from commit 9541354ec7356a4458c8568311bee2c51319209b) # Conflicts: # erpnext/e_commerce/doctype/website_item/website_item.py --- .../recommended_items/recommended_items.json | 5 ++-- .../doctype/website_item/website_item.js | 4 --- .../doctype/website_item/website_item.json | 22 +++++++--------- .../doctype/website_item/website_item.py | 25 +++++++++++-------- .../e_commerce/doctype/wishlist/wishlist.py | 12 +++++++-- erpnext/e_commerce/product_ui/grid.js | 2 +- erpnext/e_commerce/product_ui/list.js | 2 +- erpnext/patches/v13_0/create_website_items.py | 2 +- erpnext/portal/doctype/homepage/homepage.py | 4 +-- .../templates/generators/item/item_image.html | 2 +- erpnext/templates/includes/macros.html | 2 +- 11 files changed, 43 insertions(+), 39 deletions(-) diff --git a/erpnext/e_commerce/doctype/recommended_items/recommended_items.json b/erpnext/e_commerce/doctype/recommended_items/recommended_items.json index 06ac3dc03b7..18215323231 100644 --- a/erpnext/e_commerce/doctype/recommended_items/recommended_items.json +++ b/erpnext/e_commerce/doctype/recommended_items/recommended_items.json @@ -48,7 +48,7 @@ "read_only": 1 }, { - "fetch_from": "website_item.image", + "fetch_from": "website_item.website_image", "fieldname": "website_item_image", "fieldtype": "Attach", "label": "Website Item Image", @@ -75,7 +75,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-07-13 21:02:19.031652", + "modified": "2022-06-28 16:44:24.718728", "modified_by": "Administrator", "module": "E-commerce", "name": "Recommended Items", @@ -83,5 +83,6 @@ "permissions": [], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/e_commerce/doctype/website_item/website_item.js b/erpnext/e_commerce/doctype/website_item/website_item.js index 7295e4b56a0..7b7193e833a 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item.js +++ b/erpnext/e_commerce/doctype/website_item/website_item.js @@ -30,10 +30,6 @@ frappe.ui.form.on('Website Item', { }, __("View")); }, - image: () => { - refresh_field("image_view"); - }, - copy_from_item_group: (frm) => { return frm.call({ doc: frm.doc, diff --git a/erpnext/e_commerce/doctype/website_item/website_item.json b/erpnext/e_commerce/doctype/website_item/website_item.json index 245042addb8..a416aac3a17 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item.json +++ b/erpnext/e_commerce/doctype/website_item/website_item.json @@ -22,7 +22,6 @@ "column_break_11", "description", "brand", - "image", "display_section", "website_image", "website_image_alt", @@ -113,8 +112,11 @@ { "description": "Item Image (if not slideshow)", "fieldname": "website_image", - "fieldtype": "Attach", - "label": "Website Image" + "fieldtype": "Attach Image", + "hidden": 1, + "in_preview": 1, + "label": "Website Image", + "print_hide": 1 }, { "description": "Image Alternative Text", @@ -188,14 +190,6 @@ "options": "Item Group", "read_only": 1 }, - { - "fieldname": "image", - "fieldtype": "Attach Image", - "hidden": 1, - "in_preview": 1, - "label": "Image", - "print_hide": 1 - }, { "default": "1", "fieldname": "published", @@ -348,13 +342,14 @@ } ], "has_web_view": 1, - "image_field": "image", + "image_field": "website_image", "index_web_pages_for_search": 1, "links": [], - "modified": "2021-09-02 13:08:41.942726", + "modified": "2022-06-28 17:10:30.613251", "modified_by": "Administrator", "module": "E-commerce", "name": "Website Item", + "naming_rule": "Expression (old style)", "owner": "Administrator", "permissions": [ { @@ -410,6 +405,7 @@ "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "title_field": "web_item_name", "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/e_commerce/doctype/website_item/website_item.py b/erpnext/e_commerce/doctype/website_item/website_item.py index 399958b7c62..557ac7b8eed 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item.py +++ b/erpnext/e_commerce/doctype/website_item/website_item.py @@ -116,11 +116,15 @@ class WebsiteItem(WebsiteGenerator): if frappe.flags.in_import: return +<<<<<<< HEAD auto_set_website_image = False if not self.website_image and self.image: auto_set_website_image = True self.website_image = self.image +======= + """Validate if the website image is a public file""" +>>>>>>> 9541354ec7 (chore: Make `image` field obsolete in Website Item (redundant)) if not self.website_image: return @@ -137,18 +141,16 @@ class WebsiteItem(WebsiteGenerator): file_doc = file_doc[0] if not file_doc: - if not auto_set_website_image: - frappe.msgprint( - _("Website Image {0} attached to Item {1} cannot be found").format( - self.website_image, self.name - ) + frappe.msgprint( + _("Website Image {0} attached to Item {1} cannot be found").format( + self.website_image, self.name ) + ) self.website_image = None elif file_doc.is_private: - if not auto_set_website_image: - frappe.msgprint(_("Website Image should be a public file or website URL")) + frappe.msgprint(_("Website Image should be a public file or website URL")) self.website_image = None @@ -159,9 +161,8 @@ class WebsiteItem(WebsiteGenerator): import requests.exceptions - if not self.is_new() and self.website_image != frappe.db.get_value( - self.doctype, self.name, "website_image" - ): + db_website_image = frappe.db.get_value(self.doctype, self.name, "website_image") + if not self.is_new() and self.website_image != db_website_image: self.thumbnail = None if self.website_image and not self.thumbnail: @@ -457,7 +458,6 @@ def make_website_item(doc, save=True): "item_group", "stock_uom", "brand", - "image", "has_variants", "variant_of", "description", @@ -465,6 +465,9 @@ def make_website_item(doc, save=True): for field in fields_to_map: website_item.update({field: doc.get(field)}) + if doc.get("image") and not website_item.website_image: + website_item.website_image = doc.get("image") + if not save: return website_item diff --git a/erpnext/e_commerce/doctype/wishlist/wishlist.py b/erpnext/e_commerce/doctype/wishlist/wishlist.py index ec3174c25b1..75909aa27d8 100644 --- a/erpnext/e_commerce/doctype/wishlist/wishlist.py +++ b/erpnext/e_commerce/doctype/wishlist/wishlist.py @@ -20,7 +20,15 @@ def add_to_wishlist(item_code): web_item_data = frappe.db.get_value( "Website Item", {"item_code": item_code}, - ["image", "website_warehouse", "name", "web_item_name", "item_name", "item_group", "route"], + [ + "website_image", + "website_warehouse", + "name", + "web_item_name", + "item_name", + "item_group", + "route", + ], as_dict=1, ) @@ -30,7 +38,7 @@ def add_to_wishlist(item_code): "item_group": web_item_data.get("item_group"), "website_item": web_item_data.get("name"), "web_item_name": web_item_data.get("web_item_name"), - "image": web_item_data.get("image"), + "image": web_item_data.get("website_image"), "warehouse": web_item_data.get("website_warehouse"), "route": web_item_data.get("route"), } diff --git a/erpnext/e_commerce/product_ui/grid.js b/erpnext/e_commerce/product_ui/grid.js index 9eb1d45d5f5..20a6c30b52b 100644 --- a/erpnext/e_commerce/product_ui/grid.js +++ b/erpnext/e_commerce/product_ui/grid.js @@ -35,7 +35,7 @@ erpnext.ProductGrid = class { } get_image_html(item, title) { - let image = item.website_image || item.image; + let image = item.website_image; if (image) { return ` diff --git a/erpnext/e_commerce/product_ui/list.js b/erpnext/e_commerce/product_ui/list.js index 691cd4d9de1..894a7cb3d87 100644 --- a/erpnext/e_commerce/product_ui/list.js +++ b/erpnext/e_commerce/product_ui/list.js @@ -35,7 +35,7 @@ erpnext.ProductList = class { } get_image_html(item, title, settings) { - let image = item.website_image || item.image; + let image = item.website_image; let wishlist_enabled = !item.has_variants && settings.enable_wishlist; let image_html = ``; diff --git a/erpnext/patches/v13_0/create_website_items.py b/erpnext/patches/v13_0/create_website_items.py index 1a1d79ca828..01c164960f5 100644 --- a/erpnext/patches/v13_0/create_website_items.py +++ b/erpnext/patches/v13_0/create_website_items.py @@ -17,7 +17,6 @@ def execute(): "item_group", "stock_uom", "brand", - "image", "has_variants", "variant_of", "description", @@ -30,6 +29,7 @@ def execute(): "website_warehouse", "web_long_description", "website_content", + "website_image", "thumbnail", ] diff --git a/erpnext/portal/doctype/homepage/homepage.py b/erpnext/portal/doctype/homepage/homepage.py index 5bb05f0842d..0d2e3607881 100644 --- a/erpnext/portal/doctype/homepage/homepage.py +++ b/erpnext/portal/doctype/homepage/homepage.py @@ -16,7 +16,7 @@ class Homepage(Document): def setup_items(self): for d in frappe.get_all( "Website Item", - fields=["name", "item_name", "description", "image", "route"], + fields=["name", "item_name", "description", "website_image", "route"], filters={"published": 1}, limit=3, ): @@ -31,7 +31,7 @@ class Homepage(Document): item_code=d.name, item_name=d.item_name, description=d.description, - image=d.image, + image=d.website_image, route=d.route, ), ) diff --git a/erpnext/templates/generators/item/item_image.html b/erpnext/templates/generators/item/item_image.html index 930bb7a67d6..e1bb3b98655 100644 --- a/erpnext/templates/generators/item/item_image.html +++ b/erpnext/templates/generators/item/item_image.html @@ -24,7 +24,7 @@ }) {% else %} - {{ product_image(doc.website_image or doc.image, alt=doc.website_image_alt or doc.item_name) }} + {{ product_image(doc.website_image, alt=doc.website_image_alt or doc.item_name) }} {% endif %} diff --git a/erpnext/templates/includes/macros.html b/erpnext/templates/includes/macros.html index fb4cecf8266..3e20e50c3d8 100644 --- a/erpnext/templates/includes/macros.html +++ b/erpnext/templates/includes/macros.html @@ -74,7 +74,7 @@ {%- set col_size = 3 if is_full_width else 4 -%} {%- set title = item.web_item_name or item.item_name or item.item_code -%} {%- set title = title[:50] + "..." if title|len > 50 else title -%} -{%- set image = item.website_image or item.image -%} +{%- set image = item.website_image -%} {%- set description = item.website_description or item.description-%} {% if is_featured %} From 0e469f6d955e311e71b9e07c65567417ba7dacac Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 5 Jul 2022 20:30:17 +0530 Subject: [PATCH 11/14] chore: Remove `image` from ProductQuery fields (cherry picked from commit eec07833f4070ae1bdc9b829f83f6589d2591e0c) --- erpnext/e_commerce/product_data_engine/query.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/e_commerce/product_data_engine/query.py b/erpnext/e_commerce/product_data_engine/query.py index 9e0bbf4635c..d17b7cafc5e 100644 --- a/erpnext/e_commerce/product_data_engine/query.py +++ b/erpnext/e_commerce/product_data_engine/query.py @@ -35,7 +35,6 @@ class ProductQuery: "variant_of", "has_variants", "item_group", - "image", "web_long_description", "short_description", "route", From a8da5f456635517b12d8434f6e6a337c1e7259db Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 7 Jul 2022 14:24:32 +0530 Subject: [PATCH 12/14] chore: Remove `image` use in website item list (cherry picked from commit 7a6ee8cf2d3ee60f464f85f53890354d58dac4ca) --- erpnext/e_commerce/doctype/website_item/website_item_list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/e_commerce/doctype/website_item/website_item_list.js b/erpnext/e_commerce/doctype/website_item/website_item_list.js index 21be9428eb6..b9dd9214a38 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item_list.js +++ b/erpnext/e_commerce/doctype/website_item/website_item_list.js @@ -1,5 +1,5 @@ frappe.listview_settings['Website Item'] = { - add_fields: ["item_name", "web_item_name", "published", "image", "has_variants", "variant_of"], + add_fields: ["item_name", "web_item_name", "published", "website_image", "has_variants", "variant_of"], filters: [["published", "=", "1"]], get_indicator: function(doc) { From 9b1544aa14c50259fba88507ad921a7c4bc8715a Mon Sep 17 00:00:00 2001 From: marination Date: Wed, 27 Jul 2022 14:09:49 +0530 Subject: [PATCH 13/14] fix: Map `Item` image to `Website Item` website_image only if published via UI (v13) - For v12 Items, `website_image` should be mapped from `Item` to `Website Item` (cherry picked from commit af38baeb3ba48d1b9e8eeb7b727c26eea8524945) # Conflicts: # erpnext/e_commerce/doctype/website_item/website_item.py --- .../doctype/website_item/website_item.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/erpnext/e_commerce/doctype/website_item/website_item.py b/erpnext/e_commerce/doctype/website_item/website_item.py index 557ac7b8eed..1f2d7078ca1 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item.py +++ b/erpnext/e_commerce/doctype/website_item/website_item.py @@ -1,7 +1,16 @@ +<<<<<<< HEAD # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +======= +# -*- coding: utf-8 -*- +# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors +>>>>>>> af38baeb3b (fix: Map `Item` image to `Website Item` website_image only if published via UI (v13)) # For license information, please see license.txt import json +from typing import TYPE_CHECKING, List, Union + +if TYPE_CHECKING: + from erpnext.stock.doctype.item.item import Item import frappe from frappe import _ @@ -438,7 +447,9 @@ def check_if_user_is_customer(user=None): @frappe.whitelist() -def make_website_item(doc, save=True): +def make_website_item(doc: "Item", save: bool = True) -> Union["WebsiteItem", List[str]]: + "Make Website Item from Item. Used via Form UI or patch." + if not doc: return @@ -465,7 +476,8 @@ def make_website_item(doc, save=True): for field in fields_to_map: website_item.update({field: doc.get(field)}) - if doc.get("image") and not website_item.website_image: + # Needed for publishing/mapping via Form UI only + if not frappe.flags.in_migrate and (doc.get("image") and not website_item.website_image): website_item.website_image = doc.get("image") if not save: From e310347ca477e49a6ab3d66f5df288771baf0494 Mon Sep 17 00:00:00 2001 From: Marica Date: Wed, 27 Jul 2022 15:51:01 +0530 Subject: [PATCH 14/14] chore: Merge Conflicts --- .../doctype/website_item/website_item.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/erpnext/e_commerce/doctype/website_item/website_item.py b/erpnext/e_commerce/doctype/website_item/website_item.py index 1f2d7078ca1..1a750c408bb 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item.py +++ b/erpnext/e_commerce/doctype/website_item/website_item.py @@ -1,9 +1,4 @@ -<<<<<<< HEAD -# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors -======= -# -*- coding: utf-8 -*- # Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors ->>>>>>> af38baeb3b (fix: Map `Item` image to `Website Item` website_image only if published via UI (v13)) # For license information, please see license.txt import json @@ -125,15 +120,6 @@ class WebsiteItem(WebsiteGenerator): if frappe.flags.in_import: return -<<<<<<< HEAD - auto_set_website_image = False - if not self.website_image and self.image: - auto_set_website_image = True - self.website_image = self.image - -======= - """Validate if the website image is a public file""" ->>>>>>> 9541354ec7 (chore: Make `image` field obsolete in Website Item (redundant)) if not self.website_image: return