* fix: pos accounting dimension fieldname error (#45899)
* fix: pos accounting dimension fieldname error
* fix: method to get enabled accounting dimensions
* fix: fetch enabled accounting dimensions
* fix: clear flags for accounting_dimensions_details on_update
* refactor: validation for doctype
* fix: using get_checks_for_pl_and_bs_accounts for accounting dimensions
(cherry picked from commit 60a5f4f30d)
# Conflicts:
# erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py
* chore: resolve conflict
* chore: resolve linter issue
* fix: resolve linter issue
* chore: resolve linter issue
* chore: resolve linter issue
* chore: resolve linter issue
---------
Co-authored-by: Diptanil Saha <diptanil@frappe.io>
This commit is contained in:
@@ -41,6 +41,11 @@ class AccountingDimension(Document):
|
|||||||
self.set_fieldname_and_label()
|
self.set_fieldname_and_label()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
self.validate_doctype()
|
||||||
|
validate_column_name(self.fieldname)
|
||||||
|
self.validate_dimension_defaults()
|
||||||
|
|
||||||
|
def validate_doctype(self):
|
||||||
if self.document_type in (
|
if self.document_type in (
|
||||||
*core_doctypes_list,
|
*core_doctypes_list,
|
||||||
"Accounting Dimension",
|
"Accounting Dimension",
|
||||||
@@ -62,9 +67,6 @@ class AccountingDimension(Document):
|
|||||||
if not self.is_new():
|
if not self.is_new():
|
||||||
self.validate_document_type_change()
|
self.validate_document_type_change()
|
||||||
|
|
||||||
validate_column_name(self.fieldname)
|
|
||||||
self.validate_dimension_defaults()
|
|
||||||
|
|
||||||
def validate_document_type_change(self):
|
def validate_document_type_change(self):
|
||||||
doctype_before_save = frappe.db.get_value("Accounting Dimension", self.name, "document_type")
|
doctype_before_save = frappe.db.get_value("Accounting Dimension", self.name, "document_type")
|
||||||
if doctype_before_save != self.document_type:
|
if doctype_before_save != self.document_type:
|
||||||
@@ -103,6 +105,7 @@ class AccountingDimension(Document):
|
|||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
frappe.flags.accounting_dimensions = None
|
frappe.flags.accounting_dimensions = None
|
||||||
|
frappe.flags.accounting_dimensions_details = None
|
||||||
|
|
||||||
|
|
||||||
def make_dimension_in_accounting_doctypes(doc, doclist=None):
|
def make_dimension_in_accounting_doctypes(doc, doclist=None):
|
||||||
@@ -263,7 +266,7 @@ def get_checks_for_pl_and_bs_accounts():
|
|||||||
frappe.flags.accounting_dimensions_details = frappe.db.sql(
|
frappe.flags.accounting_dimensions_details = frappe.db.sql(
|
||||||
"""SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs
|
"""SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs
|
||||||
FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c
|
FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c
|
||||||
WHERE p.name = c.parent""",
|
WHERE p.name = c.parent AND p.disabled = 0""",
|
||||||
as_dict=1,
|
as_dict=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ from frappe.utils import cint, flt, get_time, getdate, nowdate, nowtime
|
|||||||
from frappe.utils.background_jobs import enqueue, is_job_enqueued
|
from frappe.utils.background_jobs import enqueue, is_job_enqueued
|
||||||
from frappe.utils.scheduler import is_scheduler_inactive
|
from frappe.utils.scheduler import is_scheduler_inactive
|
||||||
|
|
||||||
from erpnext.accounts.doctype.pos_profile.pos_profile import required_accounting_dimensions
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||||
|
get_checks_for_pl_and_bs_accounts,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class POSInvoiceMergeLog(Document):
|
class POSInvoiceMergeLog(Document):
|
||||||
@@ -292,22 +294,23 @@ class POSInvoiceMergeLog(Document):
|
|||||||
invoice.disable_rounded_total = cint(
|
invoice.disable_rounded_total = cint(
|
||||||
frappe.db.get_value("POS Profile", invoice.pos_profile, "disable_rounded_total")
|
frappe.db.get_value("POS Profile", invoice.pos_profile, "disable_rounded_total")
|
||||||
)
|
)
|
||||||
accounting_dimensions = required_accounting_dimensions()
|
accounting_dimensions = get_checks_for_pl_and_bs_accounts()
|
||||||
|
accounting_dimensions_fields = [d.fieldname for d in accounting_dimensions]
|
||||||
dimension_values = frappe.db.get_value(
|
dimension_values = frappe.db.get_value(
|
||||||
"POS Profile", {"name": invoice.pos_profile}, accounting_dimensions, as_dict=1
|
"POS Profile", {"name": invoice.pos_profile}, accounting_dimensions_fields, as_dict=1
|
||||||
)
|
)
|
||||||
for dimension in accounting_dimensions:
|
for dimension in accounting_dimensions:
|
||||||
dimension_value = dimension_values.get(dimension)
|
dimension_value = dimension_values.get(dimension.fieldname)
|
||||||
|
|
||||||
if not dimension_value:
|
if not dimension_value and (dimension.mandatory_for_pl or dimension.mandatory_for_bs):
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("Please set Accounting Dimension {} in {}").format(
|
_("Please set Accounting Dimension {} in {}").format(
|
||||||
frappe.bold(frappe.unscrub(dimension)),
|
frappe.bold(dimension.label),
|
||||||
frappe.get_desk_link("POS Profile", invoice.pos_profile),
|
frappe.get_desk_link("POS Profile", invoice.pos_profile),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
invoice.set(dimension, dimension_value)
|
invoice.set(dimension.fieldname, dimension_value)
|
||||||
|
|
||||||
if self.merge_invoices_based_on == "Customer Group":
|
if self.merge_invoices_based_on == "Customer Group":
|
||||||
invoice.flags.ignore_pos_profile = True
|
invoice.flags.ignore_pos_profile = True
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ from frappe import _, msgprint, scrub, unscrub
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import get_link_to_form, now
|
from frappe.utils import get_link_to_form, now
|
||||||
|
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||||
|
get_checks_for_pl_and_bs_accounts,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class POSProfile(Document):
|
class POSProfile(Document):
|
||||||
# begin: auto-generated types
|
# begin: auto-generated types
|
||||||
@@ -70,15 +74,15 @@ class POSProfile(Document):
|
|||||||
self.validate_accounting_dimensions()
|
self.validate_accounting_dimensions()
|
||||||
|
|
||||||
def validate_accounting_dimensions(self):
|
def validate_accounting_dimensions(self):
|
||||||
acc_dim_names = required_accounting_dimensions()
|
acc_dims = get_checks_for_pl_and_bs_accounts()
|
||||||
for acc_dim in acc_dim_names:
|
for acc_dim in acc_dims:
|
||||||
if not self.get(acc_dim):
|
if not self.get(acc_dim.fieldname) and (acc_dim.mandatory_for_pl or acc_dim.mandatory_for_bs):
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_(
|
_(
|
||||||
"{0} is a mandatory Accounting Dimension. <br>"
|
"{0} is a mandatory Accounting Dimension. <br>"
|
||||||
"Please set a value for {0} in Accounting Dimensions section."
|
"Please set a value for {0} in Accounting Dimensions section."
|
||||||
).format(
|
).format(
|
||||||
unscrub(frappe.bold(acc_dim)),
|
frappe.bold(acc_dim.label),
|
||||||
),
|
),
|
||||||
title=_("Mandatory Accounting Dimension"),
|
title=_("Mandatory Accounting Dimension"),
|
||||||
)
|
)
|
||||||
@@ -216,23 +220,6 @@ def get_child_nodes(group_type, root):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def required_accounting_dimensions():
|
|
||||||
p = frappe.qb.DocType("Accounting Dimension")
|
|
||||||
c = frappe.qb.DocType("Accounting Dimension Detail")
|
|
||||||
|
|
||||||
acc_dim_doc = (
|
|
||||||
frappe.qb.from_(p)
|
|
||||||
.inner_join(c)
|
|
||||||
.on(p.name == c.parent)
|
|
||||||
.select(c.parent)
|
|
||||||
.where((c.mandatory_for_bs == 1) | (c.mandatory_for_pl == 1))
|
|
||||||
.where(p.disabled == 0)
|
|
||||||
).run(as_dict=1)
|
|
||||||
|
|
||||||
acc_dim_names = [scrub(d.parent) for d in acc_dim_doc]
|
|
||||||
return acc_dim_names
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@frappe.validate_and_sanitize_search_inputs
|
@frappe.validate_and_sanitize_search_inputs
|
||||||
def pos_profile_query(doctype, txt, searchfield, start, page_len, filters):
|
def pos_profile_query(doctype, txt, searchfield, start, page_len, filters):
|
||||||
|
|||||||
Reference in New Issue
Block a user