Merge pull request #20864 from deepeshgarg007/po_supplier_skip

feat: Allow PI creation without PO
This commit is contained in:
Marica 2020-04-06 12:15:42 +05:30 committed by GitHub
commit b37f0bb052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 10 deletions

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe, erpnext
from frappe.utils import cint, cstr, formatdate, flt, getdate, nowdate
from frappe.utils import cint, cstr, formatdate, flt, getdate, nowdate, get_link_to_form
from frappe import _, throw
import frappe.defaults
@ -271,16 +271,30 @@ class PurchaseInvoice(BuyingController):
def po_required(self):
if frappe.db.get_value("Buying Settings", None, "po_required") == 'Yes':
if frappe.get_value('Supplier', self.supplier, 'allow_purchase_invoice_creation_without_purchase_order'):
return
for d in self.get('items'):
if not d.purchase_order:
throw(_("As per the Buying Settings if Purchase Order Required == 'YES', then for creating Purchase Invoice, user need to create Purchase Order first for item {0}").format(d.item_code))
throw(_("""Purchase Order Required for item {0}
To submit the invoice without purchase order please set
{1} as {2} in {3}""").format(frappe.bold(d.item_code), frappe.bold(_('Purchase Order Required')),
frappe.bold('No'), get_link_to_form('Buying Settings', 'Buying Settings', 'Buying Settings')))
def pr_required(self):
stock_items = self.get_stock_items()
if frappe.db.get_value("Buying Settings", None, "pr_required") == 'Yes':
if frappe.get_value('Supplier', self.supplier, 'allow_purchase_invoice_creation_without_purchase_receipt'):
return
for d in self.get('items'):
if not d.purchase_receipt and d.item_code in stock_items:
throw(_("As per the Buying Settings if Purchase Reciept Required == 'YES', then for creating Purchase Invoice, user need to create Purchase Receipt first for item {0}").format(d.item_code))
throw(_("""Purchase Receipt Required for item {0}
To submit the invoice without purchase receipt please set
{1} as {2} in {3}""").format(frappe.bold(d.item_code), frappe.bold(_('Purchase Receipt Required')),
frappe.bold('No'), get_link_to_form('Buying Settings', 'Buying Settings', 'Buying Settings')))
def validate_write_off_account(self):
if self.write_off_amount and not self.write_off_account:

View File

@ -550,12 +550,17 @@ class SalesInvoice(SellingController):
"""check in manage account if sales order / delivery note required or not."""
if self.is_return:
return
dic = {'Sales Order':['so_required', 'is_pos'],'Delivery Note':['dn_required', 'update_stock']}
for i in dic:
if frappe.db.get_single_value('Selling Settings', dic[i][0]) == 'Yes':
prev_doc_field_map = {'Sales Order': ['so_required', 'is_pos'],'Delivery Note': ['dn_required', 'update_stock']}
for key, value in iteritems(prev_doc_field_map):
if frappe.db.get_single_value('Selling Settings', value[0]) == 'Yes':
if frappe.get_value('Customer', self.customer, value[0]):
continue
for d in self.get('items'):
if (d.item_code and not d.get(i.lower().replace(' ','_')) and not self.get(dic[i][1])):
msgprint(_("{0} is mandatory for Item {1}").format(i,d.item_code), raise_exception=1)
if (d.item_code and not d.get(key.lower().replace(' ', '_')) and not self.get(value[1])):
msgprint(_("{0} is mandatory for Item {1}").format(key, d.item_code), raise_exception=1)
def validate_proj_cust(self):

View File

@ -27,6 +27,8 @@
"supplier_type",
"pan",
"language",
"allow_purchase_invoice_creation_without_purchase_order",
"allow_purchase_invoice_creation_without_purchase_receipt",
"disabled",
"warn_rfqs",
"warn_pos",
@ -364,13 +366,25 @@
"fieldname": "is_frozen",
"fieldtype": "Check",
"label": "Is Frozen"
},
{
"default": "0",
"fieldname": "allow_purchase_invoice_creation_without_purchase_order",
"fieldtype": "Check",
"label": "Allow Purchase Invoice Creation Without Purchase Order"
},
{
"default": "0",
"fieldname": "allow_purchase_invoice_creation_without_purchase_receipt",
"fieldtype": "Check",
"label": "Allow Purchase Invoice Creation Without Purchase Receipt"
}
],
"icon": "fa fa-user",
"idx": 370,
"image_field": "image",
"links": [],
"modified": "2019-12-19 18:17:16.614567",
"modified": "2020-03-17 09:48:30.578242",
"modified_by": "Administrator",
"module": "Buying",
"name": "Supplier",

View File

@ -25,6 +25,8 @@
"territory",
"tax_id",
"tax_category",
"so_required",
"dn_required",
"disabled",
"is_internal_customer",
"represents_company",
@ -465,13 +467,25 @@
"fieldtype": "Table",
"label": "Credit Limit",
"options": "Customer Credit Limit"
},
{
"default": "0",
"fieldname": "so_required",
"fieldtype": "Check",
"label": "Allow Sales Invoice Creation Without Sales Order"
},
{
"default": "0",
"fieldname": "dn_required",
"fieldtype": "Check",
"label": "Allow Sales Invoice Creation Without Delivery Note"
}
],
"icon": "fa fa-user",
"idx": 363,
"image_field": "image",
"links": [],
"modified": "2020-01-29 20:36:37.879581",
"modified": "2020-03-17 11:03:42.706907",
"modified_by": "Administrator",
"module": "Selling",
"name": "Customer",