mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 16:04:46 +00:00
[merge] [minor] merged with master
This commit is contained in:
@@ -9,17 +9,8 @@ from core.doctype.communication.communication import make
|
||||
|
||||
def add_sales_communication(subject, content, sender, real_name, mail=None,
|
||||
status="Open", date=None):
|
||||
def set_status(doctype, name):
|
||||
w = webnotes.bean(doctype, name)
|
||||
w.ignore_permissions = True
|
||||
w.doc.status = is_system_user and "Replied" or status
|
||||
w.doc.save()
|
||||
if mail:
|
||||
mail.save_attachments_in_doc(w.doc)
|
||||
|
||||
lead_name = webnotes.conn.get_value("Lead", {"email_id": sender})
|
||||
contact_name = webnotes.conn.get_value("Contact", {"email_id": sender})
|
||||
is_system_user = webnotes.conn.get_value("Profile", sender)
|
||||
|
||||
if not (lead_name or contact_name):
|
||||
# none, create a new Lead
|
||||
@@ -34,14 +25,13 @@ def add_sales_communication(subject, content, sender, real_name, mail=None,
|
||||
lead.insert()
|
||||
lead_name = lead.doc.name
|
||||
|
||||
make(content=content, sender=sender, subject=subject,
|
||||
message = make(content=content, sender=sender, subject=subject,
|
||||
lead=lead_name, contact=contact_name, date=date)
|
||||
|
||||
if contact_name:
|
||||
set_status("Contact", contact_name)
|
||||
elif lead_name:
|
||||
set_status("Lead", lead_name)
|
||||
|
||||
if mail:
|
||||
# save attachments to parent if from mail
|
||||
bean = webnotes.bean("Contact" if contact_name else "Lead", contact_name or lead_name)
|
||||
mail.save_attachments_in_doc(bean.doc)
|
||||
|
||||
class SalesMailbox(POP3Mailbox):
|
||||
def setup(self, args=None):
|
||||
|
||||
@@ -39,17 +39,14 @@ class DocType(SellingController):
|
||||
|
||||
def validate(self):
|
||||
if self.doc.status == 'Lead Lost' and not self.doc.order_lost_reason:
|
||||
msgprint("Please Enter Lost Reason under More Info section")
|
||||
raise Exception
|
||||
webnotes.throw("Please Enter Lost Reason under More Info section")
|
||||
|
||||
if self.doc.source == 'Campaign' and not self.doc.campaign_name and session['user'] != 'Guest':
|
||||
msgprint("Please specify campaign name")
|
||||
raise Exception
|
||||
webnotes.throw("Please specify campaign name")
|
||||
|
||||
if self.doc.email_id:
|
||||
if not validate_email_add(self.doc.email_id):
|
||||
msgprint('Please enter valid email id.')
|
||||
raise Exception
|
||||
webnotes.throw('Please enter valid email id.')
|
||||
|
||||
def on_update(self):
|
||||
self.check_email_id_is_unique()
|
||||
|
||||
@@ -95,7 +95,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
return{
|
||||
query : "selling.doctype.sales_common.sales_common.get_batch_no",
|
||||
filters: {
|
||||
'item': item.item_code,
|
||||
'item_code': item.item_code,
|
||||
'posting_date': me.frm.doc.posting_date
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
|
||||
and batch_no like '%(txt)s'
|
||||
and exists(select * from `tabBatch`
|
||||
where name = sle.batch_no
|
||||
and expiry_date >= '%(posting_date)s'
|
||||
and (ifnull(expiry_date, '')='' or expiry_date >= '%(posting_date)s')
|
||||
and docstatus != 2)
|
||||
%(mcond)s
|
||||
group by batch_no having sum(actual_qty) > 0
|
||||
@@ -353,11 +353,11 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
|
||||
return webnotes.conn.sql("""select name from tabBatch
|
||||
where docstatus != 2
|
||||
and item = '%(item_code)s'
|
||||
and expiry_date >= '%(posting_date)s'
|
||||
and (ifnull(expiry_date, '')='' or expiry_date >= '%(posting_date)s')
|
||||
and name like '%(txt)s'
|
||||
%(mcond)s
|
||||
order by name desc
|
||||
limit %(start)s, %(page_len)s""" % {'item_code': filters['item_code'],
|
||||
'posting_date': filters['posting_date'], 'txt': "%%%s%%" % txt,
|
||||
'mcond':get_match_cond(doctype, searchfield),'start': start,
|
||||
'page_len': page_len})
|
||||
'page_len': page_len})
|
||||
|
||||
@@ -126,8 +126,9 @@ class DocType(SellingController):
|
||||
self.validate_mandatory()
|
||||
self.validate_proj_cust()
|
||||
self.validate_po()
|
||||
self.validate_uom_is_integer("stock_uom", "qty")
|
||||
self.validate_uom_is_integer("stock_uom", "qty")
|
||||
self.validate_for_items()
|
||||
self.validate_warehouse_user()
|
||||
sales_com_obj = get_obj(dt = 'Sales Common')
|
||||
sales_com_obj.check_active_sales_items(self)
|
||||
sales_com_obj.check_conversion_rate(self)
|
||||
@@ -147,6 +148,16 @@ class DocType(SellingController):
|
||||
if not self.doc.billing_status: self.doc.billing_status = 'Not Billed'
|
||||
if not self.doc.delivery_status: self.doc.delivery_status = 'Not Delivered'
|
||||
|
||||
|
||||
def validate_warehouse_user(self):
|
||||
from stock.utils import validate_warehouse_user
|
||||
|
||||
warehouses = list(set([d.reserved_warehouse for d in
|
||||
self.doclist.get({"doctype": self.tname}) if d.reserved_warehouse]))
|
||||
|
||||
for w in warehouses:
|
||||
validate_warehouse_user(w)
|
||||
|
||||
def validate_with_previous_doc(self):
|
||||
super(DocType, self).validate_with_previous_doc(self.tname, {
|
||||
"Quotation": {
|
||||
|
||||
@@ -272,6 +272,29 @@ class TestSalesOrder(unittest.TestCase):
|
||||
self.check_reserved_qty(sbom_test_records[0][2]["item_code"],
|
||||
so.doclist[1].reserved_warehouse, 20.0)
|
||||
|
||||
def test_warehouse_user(self):
|
||||
webnotes.session.user = "test@example.com"
|
||||
|
||||
webnotes.bean("Profile", "test@example.com").get_controller()\
|
||||
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
|
||||
|
||||
webnotes.bean("Profile", "test2@example.com").get_controller()\
|
||||
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
|
||||
|
||||
|
||||
from stock.utils import UserNotAllowedForWarehouse
|
||||
so = webnotes.bean(copy = test_records[0])
|
||||
so.doc.company = "_Test Company 1"
|
||||
so.doc.conversion_rate = 0.02
|
||||
so.doc.plc_conversion_rate = 0.02
|
||||
so.doclist[1].reserved_warehouse = "_Test Warehouse 2 - _TC1"
|
||||
self.assertRaises(UserNotAllowedForWarehouse, so.insert)
|
||||
|
||||
webnotes.session.user = "test2@example.com"
|
||||
so.insert()
|
||||
|
||||
webnotes.session.user = "Administrator"
|
||||
|
||||
test_dependencies = ["Sales BOM"]
|
||||
|
||||
test_records = [
|
||||
|
||||
Reference in New Issue
Block a user