Merge pull request #30450 from anupamvs/crm-contract-naming-v13

feat: configurable Contract naming
This commit is contained in:
rohitwaghchaure
2022-04-02 23:43:02 +05:30
committed by GitHub
4 changed files with 50 additions and 12 deletions

View File

@@ -2,6 +2,17 @@
// For license information, please see license.txt
frappe.ui.form.on("Contract", {
onload: function(frm) {
frappe.db.get_value(
"Selling Settings",
"Selling Settings",
"contract_naming_by",
(r) => {
frm.toggle_display("naming_series", r.contract_naming_by === "Naming Series");
}
);
},
contract_template: function (frm) {
if (frm.doc.contract_template) {
frappe.call({

View File

@@ -2,11 +2,13 @@
"actions": [],
"allow_import": 1,
"allow_rename": 1,
"autoname": "naming_series:",
"creation": "2018-04-12 06:32:04.582486",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"naming_series",
"party_type",
"is_signed",
"cb_party",
@@ -244,11 +246,20 @@
"fieldname": "authorised_by_section",
"fieldtype": "Section Break",
"label": "Authorised By"
},
{
"fieldname": "naming_series",
"fieldtype": "Select",
"label": "Naming Series",
"no_copy": 1,
"options": "CRM-CONTR-.YYYY.-",
"reqd": 1,
"set_only_once": 1
}
],
"is_submittable": 1,
"links": [],
"modified": "2020-12-07 11:15:58.385521",
"modified": "2022-03-28 10:22:11.156658",
"modified_by": "Administrator",
"module": "CRM",
"name": "Contract",

View File

@@ -5,22 +5,32 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.model.naming import set_name_by_naming_series
from frappe.utils import getdate, nowdate
class Contract(Document):
def autoname(self):
name = self.party_name
if frappe.db.get_single_value("Selling Settings", "contract_naming_by") == "Naming Series":
set_name_by_naming_series(self)
if self.contract_template:
name += " - {} Agreement".format(self.contract_template)
else:
name = self.party_name
# If identical, append contract name with the next number in the iteration
if frappe.db.exists("Contract", name):
count = len(frappe.get_all("Contract", filters={"name": ["like", "%{}%".format(name)]}))
name = "{} - {}".format(name, count)
if self.contract_template:
name = f"{name} - {self.contract_template} Agreement"
self.name = _(name)
# If identical, append contract name with the next number in the iteration
if frappe.db.exists("Contract", name):
count = frappe.db.count(
"Contract",
filters={
"name": ("like", f"%{name}%"),
},
)
name = f"{name} - {count}"
self.name = _(name)
def validate(self):
self.validate_dates()

View File

@@ -13,6 +13,7 @@
"territory",
"crm_settings_section",
"campaign_naming_by",
"contract_naming_by",
"default_valid_till",
"column_break_9",
"close_opportunity_after_days",
@@ -29,7 +30,6 @@
"so_required",
"dn_required",
"sales_update_frequency",
"column_break_5",
"allow_multiple_items",
"allow_against_multiple_purchase_orders",
"hide_tax_id"
@@ -193,6 +193,12 @@
"fieldname": "sales_transactions_settings_section",
"fieldtype": "Section Break",
"label": "Transaction Settings"
},
{
"fieldname": "contract_naming_by",
"fieldtype": "Select",
"label": "Contract Naming By",
"options": "Party Name\nNaming Series"
}
],
"icon": "fa fa-cog",
@@ -200,7 +206,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2021-09-14 22:05:06.139820",
"modified": "2022-03-28 12:18:06.768403",
"modified_by": "Administrator",
"module": "Selling",
"name": "Selling Settings",
@@ -219,4 +225,4 @@
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}
}