feat: Merge POS invoices based on customer group (#27471)

* feat: Merge POS invoices based on customer group

* fix: Linting Issues

* fix: fieldname

Co-authored-by: Saqib <nextchamp.saqib@gmail.com>
This commit is contained in:
Deepesh Garg 2021-09-16 19:33:57 +05:30 committed by GitHub
parent 5eba1ccd51
commit c9c8957250
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 7 deletions

View File

@ -4,7 +4,7 @@
frappe.ui.form.on('POS Invoice Merge Log', { frappe.ui.form.on('POS Invoice Merge Log', {
setup: function(frm) { setup: function(frm) {
frm.set_query("pos_invoice", "pos_invoices", doc => { frm.set_query("pos_invoice", "pos_invoices", doc => {
return{ return {
filters: { filters: {
'docstatus': 1, 'docstatus': 1,
'customer': doc.customer, 'customer': doc.customer,
@ -12,5 +12,10 @@ frappe.ui.form.on('POS Invoice Merge Log', {
} }
} }
}); });
},
merge_invoices_based_on: function(frm) {
frm.set_value('customer', '');
frm.set_value('customer_group', '');
} }
}); });

View File

@ -6,9 +6,11 @@
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"posting_date", "posting_date",
"customer", "merge_invoices_based_on",
"column_break_3", "column_break_3",
"pos_closing_entry", "pos_closing_entry",
"customer",
"customer_group",
"section_break_3", "section_break_3",
"pos_invoices", "pos_invoices",
"references_section", "references_section",
@ -88,12 +90,27 @@
"fieldtype": "Link", "fieldtype": "Link",
"label": "POS Closing Entry", "label": "POS Closing Entry",
"options": "POS Closing Entry" "options": "POS Closing Entry"
},
{
"fieldname": "merge_invoices_based_on",
"fieldtype": "Select",
"label": "Merge Invoices Based On",
"options": "Customer\nCustomer Group",
"reqd": 1
},
{
"depends_on": "eval:doc.merge_invoices_based_on == 'Customer Group'",
"fieldname": "customer_group",
"fieldtype": "Link",
"label": "Customer Group",
"mandatory_depends_on": "eval:doc.merge_invoices_based_on == 'Customer Group'",
"options": "Customer Group"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2020-12-01 11:53:57.267579", "modified": "2021-09-14 11:17:19.001142",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "POS Invoice Merge Log", "name": "POS Invoice Merge Log",

View File

@ -23,6 +23,9 @@ class POSInvoiceMergeLog(Document):
self.validate_pos_invoice_status() self.validate_pos_invoice_status()
def validate_customer(self): def validate_customer(self):
if self.merge_invoices_based_on == 'Customer Group':
return
for d in self.pos_invoices: for d in self.pos_invoices:
if d.customer != self.customer: if d.customer != self.customer:
frappe.throw(_("Row #{}: POS Invoice {} is not against customer {}").format(d.idx, d.pos_invoice, self.customer)) frappe.throw(_("Row #{}: POS Invoice {} is not against customer {}").format(d.idx, d.pos_invoice, self.customer))
@ -124,7 +127,7 @@ class POSInvoiceMergeLog(Document):
found = False found = False
for i in items: for i in items:
if (i.item_code == item.item_code and not i.serial_no and not i.batch_no and if (i.item_code == item.item_code and not i.serial_no and not i.batch_no and
i.uom == item.uom and i.net_rate == item.net_rate): i.uom == item.uom and i.net_rate == item.net_rate and i.warehouse == item.warehouse):
found = True found = True
i.qty = i.qty + item.qty i.qty = i.qty + item.qty
@ -172,6 +175,11 @@ class POSInvoiceMergeLog(Document):
invoice.discount_amount = 0.0 invoice.discount_amount = 0.0
invoice.taxes_and_charges = None invoice.taxes_and_charges = None
invoice.ignore_pricing_rule = 1 invoice.ignore_pricing_rule = 1
invoice.customer = self.customer
if self.merge_invoices_based_on == 'Customer Group':
invoice.flags.ignore_pos_profile = True
invoice.pos_profile = ''
return invoice return invoice
@ -228,7 +236,7 @@ def get_all_unconsolidated_invoices():
return pos_invoices return pos_invoices
def get_invoice_customer_map(pos_invoices): def get_invoice_customer_map(pos_invoices):
# pos_invoice_customer_map = { 'Customer 1': [{}, {}, {}], 'Custoemr 2' : [{}] } # pos_invoice_customer_map = { 'Customer 1': [{}, {}, {}], 'Customer 2' : [{}] }
pos_invoice_customer_map = {} pos_invoice_customer_map = {}
for invoice in pos_invoices: for invoice in pos_invoices:
customer = invoice.get('customer') customer = invoice.get('customer')

View File

@ -499,7 +499,7 @@ class SalesInvoice(SellingController):
self.account_for_change_amount = frappe.get_cached_value('Company', self.company, 'default_cash_account') self.account_for_change_amount = frappe.get_cached_value('Company', self.company, 'default_cash_account')
from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details
if not self.pos_profile: if not self.pos_profile and not self.flags.ignore_pos_profile:
pos_profile = get_pos_profile(self.company) or {} pos_profile = get_pos_profile(self.company) or {}
if not pos_profile: if not pos_profile:
return return

View File

@ -442,7 +442,7 @@ accounting_dimension_doctypes = ["GL Entry", "Sales Invoice", "Purchase Invoice"
"Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction", "Sales Taxes and Charges", "Purchase Taxes and Charges", "Shipping Rule", "Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction", "Sales Taxes and Charges", "Purchase Taxes and Charges", "Shipping Rule",
"Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation", "Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation",
"Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", "Opening Invoice Creation Tool Item", "Subscription", "Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", "Opening Invoice Creation Tool Item", "Subscription",
"Subscription Plan" "Subscription Plan", "POS Invoice", "POS Invoice Item"
] ]
regional_overrides = { regional_overrides = {

View File

@ -307,3 +307,4 @@ erpnext.patches.v14_0.delete_shopify_doctypes
erpnext.patches.v13_0.replace_supplier_item_group_with_party_specific_item erpnext.patches.v13_0.replace_supplier_item_group_with_party_specific_item
erpnext.patches.v13_0.update_dates_in_tax_withholding_category erpnext.patches.v13_0.update_dates_in_tax_withholding_category
erpnext.patches.v14_0.update_opportunity_currency_fields erpnext.patches.v14_0.update_opportunity_currency_fields
erpnext.patches.v13_0.create_accounting_dimensions_in_pos_doctypes

View File

@ -0,0 +1,42 @@
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
def execute():
frappe.reload_doc('accounts', 'doctype', 'accounting_dimension')
accounting_dimensions = frappe.db.sql("""select fieldname, label, document_type, disabled from
`tabAccounting Dimension`""", as_dict=1)
if not accounting_dimensions:
return
count = 1
for d in accounting_dimensions:
if count % 2 == 0:
insert_after_field = 'dimension_col_break'
else:
insert_after_field = 'accounting_dimensions_section'
for doctype in ["POS Invoice", "POS Invoice Item"]:
field = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": d.fieldname})
if field:
continue
meta = frappe.get_meta(doctype, cached=False)
fieldnames = [d.fieldname for d in meta.get("fields")]
df = {
"fieldname": d.fieldname,
"label": d.label,
"fieldtype": "Link",
"options": d.document_type,
"insert_after": insert_after_field
}
if df['fieldname'] not in fieldnames:
create_custom_field(doctype, df)
frappe.clear_cache(doctype=doctype)
count += 1