Browse Source

[mapper-pull] for sales / purchae

develop
Rushabh Mehta 12 years ago
parent
commit
d9e7070f2d
  1. 70
      accounts/doctype/purchase_invoice/purchase_invoice.js
  2. 11
      accounts/doctype/purchase_invoice/purchase_invoice.py
  3. 90
      accounts/doctype/sales_invoice/sales_invoice.js
  4. 14
      accounts/doctype/sales_invoice/sales_invoice.py
  5. 67
      accounts/doctype/sales_invoice/sales_invoice.txt
  6. 8
      buying/doctype/purchase_order/purchase_order.js
  7. 3
      buying/doctype/purchase_order/purchase_order.py
  8. 9
      buying/doctype/purchase_order/purchase_order.txt
  9. 3
      buying/utils.py
  10. 290
      selling/doctype/sales_common/sales_common.py
  11. 6
      selling/utils.py
  12. 2
      setup/doctype/company/company.py
  13. 42
      setup/doctype/company/company.txt
  14. 5
      stock/doctype/delivery_note/delivery_note.py
  15. 29
      stock/doctype/delivery_note/delivery_note.txt
  16. 14
      stock/doctype/delivery_note_item/delivery_note_item.txt
  17. 76
      stock/doctype/purchase_receipt/purchase_receipt.js
  18. 8
      stock/doctype/purchase_receipt/purchase_receipt.py
  19. 83
      stock/doctype/purchase_receipt/purchase_receipt.txt
  20. 12
      stock/doctype/purchase_receipt_item/purchase_receipt_item.txt

70
accounts/doctype/purchase_invoice/purchase_invoice.js

@ -51,7 +51,38 @@ erpnext.accounts.PurchaseInvoiceController = erpnext.buying.BuyingController.ext
wn.set_route("general-ledger");
});
}
if(doc.docstatus===0) {
cur_frm.add_custom_button(wn._('From Purchase Order'),
function() {
wn.model.map_current_doc({
method: "buying.doctype.purchase_order.purchase_order.make_purchase_invoice",
source_doctype: "Purchase Order",
get_query_filters: {
supplier: cur_frm.doc.supplier || undefined,
docstatus: 1,
status: ["!=", "Stopped"],
per_billed: ["<", 99.99],
company: cur_frm.doc.company
}
})
});
cur_frm.add_custom_button(wn._('From Purchase Receipt'),
function() {
wn.model.map_current_doc({
method: "stock.doctype.purchase_receipt.purchase_receipt.make_purchase_invoice",
source_doctype: "Purchase Receipt",
get_query_filters: {
supplier: cur_frm.doc.supplier || undefined,
docstatus: 1,
company: cur_frm.doc.company
}
})
});
}
this.is_opening(doc);
},
@ -68,22 +99,11 @@ erpnext.accounts.PurchaseInvoiceController = erpnext.buying.BuyingController.ext
this.calculate_total_advance("Purchase Invoice", "advance_allocation_details");
this.frm.refresh_fields();
},
get_items: function() {
if(doc.purchase_order_main) {
wn.model.map_current_doc({
method: "buying.doctype.purchase_order.purchase_order.make_purchase_invoice",
source_name: cur_frm.doc.purchase_order_main,
})
}
else if(doc.purchase_receipt_main) {
wn.model.map_current_doc({
method: "selling.doctype.purchase_receipt.purchase_receipt.make_purchase_invoice",
source_name: cur_frm.doc.purchase_receipt_main,
})
}
}
tc_name: function() {
this.get_terms();
},
});
// for backward compatibility: combine new and previous states
@ -149,22 +169,6 @@ cur_frm.fields_dict['credit_to'].get_query = function(doc) {
return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.debit_or_credit="Credit" AND tabAccount.is_pl_account="No" AND tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND tabAccount.company="'+doc.company+'" AND tabAccount.%(key)s LIKE "%s"'
}
cur_frm.fields_dict['purchase_order_main'].get_query = function(doc) {
if (doc.supplier){
return 'SELECT `tabPurchase Order`.`name` FROM `tabPurchase Order` WHERE `tabPurchase Order`.`docstatus` = 1 AND `tabPurchase Order`.supplier = "'+ doc.supplier +'" AND `tabPurchase Order`.`status` != "Stopped" AND ifnull(`tabPurchase Order`.`per_billed`,0) < 99.99 AND `tabPurchase Order`.`company` = "' + doc.company + '" AND `tabPurchase Order`.%(key)s LIKE "%s" ORDER BY `tabPurchase Order`.`name` DESC LIMIT 50'
} else {
return 'SELECT `tabPurchase Order`.`name` FROM `tabPurchase Order` WHERE `tabPurchase Order`.`docstatus` = 1 AND `tabPurchase Order`.`status` != "Stopped" AND ifnull(`tabPurchase Order`.`per_billed`, 0) < 99.99 AND `tabPurchase Order`.`company` = "' + doc.company + '" AND `tabPurchase Order`.%(key)s LIKE "%s" ORDER BY `tabPurchase Order`.`name` DESC LIMIT 50'
}
}
cur_frm.fields_dict['purchase_receipt_main'].get_query = function(doc) {
if (doc.supplier){
return 'SELECT `tabPurchase Receipt`.`name` FROM `tabPurchase Receipt` WHERE `tabPurchase Receipt`.`docstatus` = 1 AND `tabPurchase Receipt`.supplier = "'+ doc.supplier +'" AND `tabPurchase Receipt`.`status` != "Stopped" AND ifnull(`tabPurchase Receipt`.`per_billed`, 0) < 99.99 AND `tabPurchase Receipt`.`company` = "' + doc.company + '" AND `tabPurchase Receipt`.%(key)s LIKE "%s" ORDER BY `tabPurchase Receipt`.`name` DESC LIMIT 50'
} else {
return 'SELECT `tabPurchase Receipt`.`name` FROM `tabPurchase Receipt` WHERE `tabPurchase Receipt`.`docstatus` = 1 AND `tabPurchase Receipt`.`status` != "Stopped" AND ifnull(`tabPurchase Receipt`.`per_billed`, 0) < 99.99 AND `tabPurchase Receipt`.`company` = "' + doc.company + '" AND `tabPurchase Receipt`.%(key)s LIKE "%s" ORDER BY `tabPurchase Receipt`.`name` DESC LIMIT 50'
}
}
// Get Print Heading
cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) {
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';

11
accounts/doctype/purchase_invoice/purchase_invoice.py

@ -43,17 +43,6 @@ class DocType(BuyingController):
'target_ref_field': 'import_amount',
'source_field': 'import_amount',
'percent_join_field': 'purchase_order',
},
{
'source_dt': 'Purchase Invoice Item',
'target_dt': 'Purchase Receipt Item',
'join_field': 'pr_detail',
'target_field': 'billed_amt',
'target_parent_dt': 'Purchase Receipt',
'target_parent_field': 'per_billed',
'target_ref_field': 'import_amount',
'source_field': 'import_amount',
'percent_join_field': 'purchase_receipt',
}]
def validate(self):

90
accounts/doctype/sales_invoice/sales_invoice.js

@ -66,8 +66,44 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
if(doc.outstanding_amount!=0)
cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript.make_bank_voucher);
}
if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(wn._('From Sales Order'),
function() {
wn.model.map_current_doc({
method: "selling.doctype.sales_order.sales_order.make_sales_invoice",
source_doctype: "Sales Order",
get_query_filters: {
docstatus: 1,
status: ["!=", "Stopped"],
per_billed: ["<", 99.99],
customer: cur_frm.doc.customer || undefined,
company: cur_frm.doc.company
}
})
});
cur_frm.add_custom_button(wn._('From Delivery Note'),
function() {
wn.model.map_current_doc({
method: "stock.doctype.delivery_note.delivery_note.make_sales_invoice",
source_doctype: "Delivery Note",
get_query_filters: {
docstatus: 1,
customer: cur_frm.doc.customer || undefined,
company: cur_frm.doc.company
}
})
});
}
cur_frm.cscript.hide_fields(doc, dt, dn);
},
tc_name: function() {
this.get_terms();
},
is_pos: function() {
if(cint(this.frm.doc.is_pos)) {
@ -122,9 +158,8 @@ $.extend(cur_frm.cscript, new erpnext.accounts.SalesInvoiceController({frm: cur_
// Hide Fields
// ------------
cur_frm.cscript.hide_fields = function(doc, cdt, cdn) {
par_flds = ['project_name', 'due_date', 'sales_order_main',
'delivery_note_main', 'get_items', 'is_opening', 'conversion_rate',
'source', 'cancel_reason', 'total_advance', 'gross_profit',
par_flds = ['project_name', 'due_date', 'is_opening', 'conversion_rate',
'source', 'total_advance', 'gross_profit',
'gross_profit_percent', 'get_advances_received',
'advance_adjustment_details', 'sales_partner', 'commission_rate',
'total_commission', 'advances'];
@ -190,24 +225,6 @@ cur_frm.cscript.is_opening = function(doc, dt, dn) {
if (doc.is_opening == 'Yes') unhide_field('aging_date');
}
// Get Items based on SO or DN Selected
cur_frm.cscript.get_items = function(doc, dt, dn) {
if(doc.delivery_note_main) {
wn.model.map_current_doc({
method: "stock.doctype.delivery_note.delivery_note.make_sales_invoice",
source_name: cur_frm.doc.delivery_note_main,
})
}
else if(doc.sales_order_main) {
wn.model.map_current_doc({
method: "selling.doctype.sales_order.sales_order.make_sales_invoice",
source_name: cur_frm.doc.sales_order_main,
})
}
}
//Make Delivery Note Button
//-----------------------------
@ -302,37 +319,6 @@ cur_frm.fields_dict["entries"].grid.get_field("cost_center").get_query = functio
}
}
// Sales Order
// -----------
cur_frm.fields_dict.sales_order_main.get_query = function(doc) {
if (doc.customer)
return 'SELECT DISTINCT `tabSales Order`.`name` FROM `tabSales Order` WHERE `tabSales Order`.company = "' + doc.company + '" and `tabSales Order`.`docstatus` = 1 and `tabSales Order`.`status` != "Stopped" and ifnull(`tabSales Order`.per_billed,0) < 99.99 and `tabSales Order`.`customer` = "' + doc.customer + '" and `tabSales Order`.%(key)s LIKE "%s" ORDER BY `tabSales Order`.`name` DESC LIMIT 50';
else
return 'SELECT DISTINCT `tabSales Order`.`name` FROM `tabSales Order` WHERE `tabSales Order`.company = "' + doc.company + '" and `tabSales Order`.`docstatus` = 1 and `tabSales Order`.`status` != "Stopped" and ifnull(`tabSales Order`.per_billed,0) < 99.99 and `tabSales Order`.%(key)s LIKE "%s" ORDER BY `tabSales Order`.`name` DESC LIMIT 50';
}
// Delivery Note
// --------------
cur_frm.fields_dict.delivery_note_main.get_query = function(doc) {
if (doc.customer)
return 'SELECT DISTINCT `tabDelivery Note`.`name` FROM `tabDelivery Note` \
WHERE `tabDelivery Note`.company = "' + doc.company
+ '" and `tabDelivery Note`.`docstatus` = 1 and \
ifnull(`tabDelivery Note`.per_billed,0) < 99.99 and \
`tabDelivery Note`.`customer` = "'
+ doc.customer + '" and `tabDelivery Note`.%(key)s LIKE "%s" \
ORDER BY `tabDelivery Note`.`name` DESC LIMIT 50';
else
return 'SELECT DISTINCT `tabDelivery Note`.`name` FROM `tabDelivery Note` \
WHERE `tabDelivery Note`.company = "' + doc.company
+ '" and `tabDelivery Note`.`docstatus` = 1 and \
ifnull(`tabDelivery Note`.per_billed,0) < 99.99 and \
`tabDelivery Note`.%(key)s LIKE "%s" \
ORDER BY `tabDelivery Note`.`name` DESC LIMIT 50';
}
cur_frm.cscript.income_account = function(doc, cdt, cdn){
cur_frm.cscript.copy_account_in_all_row(doc, cdt, cdn, "income_account");
}

14
accounts/doctype/sales_invoice/sales_invoice.py

@ -51,20 +51,6 @@ class DocType(SellingController):
'percent_join_field': 'sales_order',
'status_field': 'billing_status',
'keyword': 'Billed'
},
{
'source_dt': 'Sales Invoice Item',
'target_dt': 'Delivery Note Item',
'join_field': 'dn_detail',
'target_field': 'billed_amt',
'target_parent_dt': 'Delivery Note',
'target_parent_field': 'per_billed',
'target_ref_field': 'export_amount',
'source_field': 'export_amount',
'percent_join_field': 'delivery_note',
'status_field': 'billing_status',
'keyword': 'Billed',
'no_tolerance': True,
}]

67
accounts/doctype/sales_invoice/sales_invoice.txt

@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:05",
"docstatus": 0,
"modified": "2013-07-05 14:54:19",
"modified": "2013-07-08 17:05:43",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -350,52 +350,6 @@
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "section_break0",
"fieldtype": "Section Break",
"read_only": 0
},
{
"description": "Select Items from Sales Order",
"doctype": "DocField",
"fieldname": "sales_order_main",
"fieldtype": "Link",
"label": "Sales Order",
"oldfieldname": "sales_order_main",
"oldfieldtype": "Link",
"options": "Sales Order",
"print_hide": 1,
"read_only": 0
},
{
"description": "Select Items from Delivery Note",
"doctype": "DocField",
"fieldname": "delivery_note_main",
"fieldtype": "Link",
"label": "Delivery Note",
"oldfieldname": "delivery_note_main",
"oldfieldtype": "Link",
"options": "Delivery Note",
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "get_items",
"fieldtype": "Button",
"label": "Get Items",
"oldfieldtype": "Button",
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "col_break25",
"fieldtype": "Column Break",
"read_only": 0,
"width": "50%"
},
{
"doctype": "DocField",
"fieldname": "net_total_export",
@ -789,25 +743,6 @@
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "column_break_71",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "get_terms",
"fieldtype": "Button",
"label": "Get Terms and Conditions",
"oldfieldtype": "Button",
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "section_break_73",
"fieldtype": "Section Break"
},
{
"doctype": "DocField",
"fieldname": "terms",

8
buying/doctype/purchase_order/purchase_order.js

@ -94,8 +94,12 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
}
})
});
}
},
tc_name: function() {
this.get_terms();
},
});
// for backward compatibility: combine new and previous states

3
buying/doctype/purchase_order/purchase_order.py

@ -243,7 +243,8 @@ def make_purchase_invoice(source_name, target_doclist=None):
target.conversion_factor = 1
target.import_amount = flt(obj.import_amount) - flt(obj.billed_amt)
target.amount = target.import_amount / flt(source_parent.conversion_rate)
target.qty = target.amount / flt(obj.purchase_rate)
if flt(obj.purchase_rate):
target.qty = target.amount / flt(obj.purchase_rate)
doclist = get_mapped_doclist("Purchase Order", source_name, {
"Purchase Order": {

9
buying/doctype/purchase_order/purchase_order.txt

@ -2,7 +2,7 @@
{
"creation": "2013-05-21 16:16:39",
"docstatus": 0,
"modified": "2013-07-08 15:12:46",
"modified": "2013-07-08 17:49:29",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -488,13 +488,6 @@
"options": "Terms and Conditions",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "get_terms",
"fieldtype": "Button",
"label": "Get Terms and Conditions",
"oldfieldtype": "Button"
},
{
"doctype": "DocField",
"fieldname": "terms",

3
buying/utils.py

@ -85,7 +85,8 @@ def _get_basic_details(args, item_bean):
"item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in
item_bean.doclist.get({"parentfield": "item_tax"})))),
"batch_no": None,
"expense_head": item.purchase_account,
"expense_head": item.purchase_account \
or webnotes.conn.get_value("Company", args.company, "default_expense_account"),
"cost_center": item.cost_center
})

290
selling/doctype/sales_common/sales_common.py

@ -335,7 +335,7 @@ class DocType(TransactionBase):
if item.is_sales_item == 'No' and item.is_service_item == 'No':
msgprint("Item : '%s' is neither Sales nor Service Item" % (d.item_code))
raise Exception
if d.income_account and not default_income_account:
if d.income_account and not item.default_income_account:
webnotes.conn.set_value("Item", d.item_code, "default_income_account", d.income_account)
@ -365,291 +365,3 @@ class DocType(TransactionBase):
dt = webnotes.conn.sql("select transaction_date from `tab%s` where name = '%s'" % (d.prevdoc_doctype, d.prevdoc_docname))
d.prevdoc_date = (dt and dt[0][0]) and dt[0][0].strftime('%Y-%m-%d') or ''
def update_prevdoc_detail(self, is_submit, obj):
StatusUpdater(obj, is_submit).update()
#
# make item code readonly if (detail no is set)
#
class StatusUpdater:
"""
Updates the status of the calling records
From Delivery Note
- Update Delivered Qty
- Update Percent
- Validate over delivery
From Sales Invoice
- Update Billed Amt
- Update Percent
- Validate over billing
From Installation Note
- Update Installed Qty
- Update Percent Qty
- Validate over installation
"""
def __init__(self, obj, is_submit):
self.obj = obj # caller object
self.is_submit = is_submit
self.tolerance = {}
self.global_tolerance = None
def update(self):
self.update_all_qty()
self.validate_all_qty()
def validate_all_qty(self):
"""
Validates over-billing / delivery / installation in Delivery Note, Sales Invoice, Installation Note
To called after update_all_qty
"""
if self.obj.doc.doctype=='Delivery Note':
self.validate_qty({
'source_dt' :'Delivery Note Item',
'compare_field' :'delivered_qty',
'compare_ref_field' :'qty',
'target_dt' :'Sales Order Item',
'join_field' :'prevdoc_detail_docname'
})
elif self.obj.doc.doctype=='Sales Invoice':
self.validate_qty({
'source_dt' :'Sales Invoice Item',
'compare_field' :'billed_amt',
'compare_ref_field' :'export_amount',
'target_dt' :'Sales Order Item',
'join_field' :'so_detail'
})
self.validate_qty({
'source_dt' :'Sales Invoice Item',
'compare_field' :'billed_amt',
'compare_ref_field' :'export_amount',
'target_dt' :'Delivery Note Item',
'join_field' :'dn_detail'
}, no_tolerance =1)
elif self.obj.doc.doctype=='Installation Note':
self.validate_qty({
'source_dt' :'Installation Item Details',
'compare_field' :'installed_qty',
'compare_ref_field' :'qty',
'target_dt' :'Delivery Note Item',
'join_field' :'dn_detail'
}, no_tolerance =1)
def get_tolerance_for(self, item_code):
"""
Returns the tolerance for the item, if not set, returns global tolerance
"""
if self.tolerance.get(item_code):
return self.tolerance[item_code]
tolerance = flt(webnotes.conn.get_value('Item',item_code,'tolerance') or 0)
if not tolerance:
if self.global_tolerance == None:
self.global_tolerance = flt(webnotes.conn.get_value('Stock Settings',None,'tolerance') or 0)
tolerance = self.global_tolerance
self.tolerance[item_code] = tolerance
return tolerance
def check_overflow_with_tolerance(self, item, args):
"""
Checks if there is overflow condering a relaxation tolerance
"""
# check if overflow is within tolerance
tolerance = self.get_tolerance_for(item['item_code'])
overflow_percent = ((item[args['compare_field']] - item[args['compare_ref_field']]) / item[args['compare_ref_field']]) * 100
if overflow_percent - tolerance > 0.01:
item['max_allowed'] = flt(item[args['compare_ref_field']] * (100+tolerance)/100)
item['reduce_by'] = item[args['compare_field']] - item['max_allowed']
msgprint("""
Row #%(idx)s: Max %(compare_ref_field)s allowed for <b>Item %(item_code)s</b> against <b>%(parenttype)s %(parent)s</b> is <b>%(max_allowed)s</b>.
If you want to increase your overflow tolerance, please increase tolerance %% in Global Defaults or Item master.
Or, you must reduce the %(compare_ref_field)s by %(reduce_by)s
Also, please check if the order item has already been billed in the Sales Order""" % item, raise_exception=1)
def validate_qty(self, args, no_tolerance=None):
"""
Validates qty at row level
"""
# get unique transactions to update
for d in self.obj.doclist:
if d.doctype == args['source_dt'] and d.fields.get(args["join_field"]):
args['name'] = d.fields[args['join_field']]
# get all qty where qty > compare_field
item = webnotes.conn.sql("""select item_code, `%(compare_ref_field)s`,
`%(compare_field)s`, parenttype, parent from `tab%(target_dt)s`
where `%(compare_ref_field)s` < `%(compare_field)s`
and name="%(name)s" and docstatus=1
""" % args, as_dict=1)
if item:
item = item[0]
item['idx'] = d.idx
item['compare_ref_field'] = args['compare_ref_field'].replace('_', ' ')
if not item[args['compare_ref_field']]:
msgprint("As %(compare_ref_field)s for item: %(item_code)s in %(parenttype)s: %(parent)s is zero, system will not check over-delivery or over-billed" % item)
elif no_tolerance:
item['reduce_by'] = item[args['compare_field']] - item[args['compare_ref_field']]
if item['reduce_by'] > .01:
msgprint("""
Row #%(idx)s: Max %(compare_ref_field)s allowed for <b>Item %(item_code)s</b> against
<b>%(parenttype)s %(parent)s</b> is <b>""" % item
+ cstr(item[args['compare_ref_field']]) + """</b>.
You must reduce the %(compare_ref_field)s by %(reduce_by)s""" % item, raise_exception=1)
else:
self.check_overflow_with_tolerance(item, args)
def update_all_qty(self):
"""
Updates delivered / billed / installed qty in Sales Order & Delivery Note
"""
if self.obj.doc.doctype=='Delivery Note':
self.update_qty({
'target_field' :'delivered_qty',
'target_dt' :'Sales Order Item',
'target_parent_dt' :'Sales Order',
'target_parent_field' :'per_delivered',
'target_ref_field' :'qty',
'source_dt' :'Delivery Note Item',
'source_field' :'qty',
'join_field' :'prevdoc_detail_docname',
'percent_join_field' :'prevdoc_docname',
'status_field' :'delivery_status',
'keyword' :'Delivered'
})
elif self.obj.doc.doctype=='Sales Invoice':
self.update_qty({
'target_field' :'billed_amt',
'target_dt' :'Sales Order Item',
'target_parent_dt' :'Sales Order',
'target_parent_field' :'per_billed',
'target_ref_field' :'export_amount',
'source_dt' :'Sales Invoice Item',
'source_field' :'export_amount',
'join_field' :'so_detail',
'percent_join_field' :'sales_order',
'status_field' :'billing_status',
'keyword' :'Billed'
})
self.update_qty({
'target_field' :'billed_amt',
'target_dt' :'Delivery Note Item',
'target_parent_dt' :'Delivery Note',
'target_parent_field' :'per_billed',
'target_ref_field' :'export_amount',
'source_dt' :'Sales Invoice Item',
'source_field' :'export_amount',
'join_field' :'dn_detail',
'percent_join_field' :'delivery_note',
'status_field' :'billing_status',
'keyword' :'Billed'
})
if cint(self.obj.doc.is_pos) == 1:
self.update_qty({
'target_field' :'delivered_qty',
'target_dt' :'Sales Order Item',
'target_parent_dt' :'Sales Order',
'target_parent_field' :'per_delivered',
'target_ref_field' :'qty',
'source_dt' :'Sales Invoice Item',
'source_field' :'qty',
'join_field' :'so_detail',
'percent_join_field' :'sales_order',
'status_field' :'delivery_status',
'keyword' :'Delivered'
})
if self.obj.doc.doctype=='Installation Note':
self.update_qty({
'target_field' :'installed_qty',
'target_dt' :'Delivery Note Item',
'target_parent_dt' :'Delivery Note',
'target_parent_field' :'per_installed',
'target_ref_field' :'qty',
'source_dt' :'Installation Note Item',
'source_field' :'qty',
'join_field' :'prevdoc_detail_docname',
'percent_join_field' :'prevdoc_docname',
'status_field' :'installation_status',
'keyword' :'Installed'
})
def update_qty(self, args):
"""
Updates qty at row level
"""
# condition to include current record (if submit or no if cancel)
if self.is_submit:
args['cond'] = ' or parent="%s"' % self.obj.doc.name
else:
args['cond'] = ' and parent!="%s"' % self.obj.doc.name
# update quantities in child table
for d in self.obj.doclist:
if d.doctype == args['source_dt']:
# updates qty in the child table
args['detail_id'] = d.fields.get(args['join_field'])
if args['detail_id']:
webnotes.conn.sql("""
update
`tab%(target_dt)s`
set
%(target_field)s = (select sum(%(source_field)s) from `tab%(source_dt)s` where `%(join_field)s`="%(detail_id)s" and (docstatus=1 %(cond)s))
where
name="%(detail_id)s"
""" % args)
# get unique transactions to update
for name in set([d.fields.get(args['percent_join_field']) for d in self.obj.doclist if d.doctype == args['source_dt']]):
if name:
args['name'] = name
# update percent complete in the parent table
webnotes.conn.sql("""
update
`tab%(target_parent_dt)s`
set
%(target_parent_field)s =
(select sum(if(%(target_ref_field)s > ifnull(%(target_field)s, 0), %(target_field)s, %(target_ref_field)s))/sum(%(target_ref_field)s)*100 from `tab%(target_dt)s` where parent="%(name)s"),
modified = now()
where
name="%(name)s"
""" % args)
# update field
if args['status_field']:
webnotes.conn.sql("""
update
`tab%(target_parent_dt)s`
set
%(status_field)s = if(ifnull(%(target_parent_field)s,0)<0.001, 'Not %(keyword)s',
if(%(target_parent_field)s>=99.99, 'Fully %(keyword)s', 'Partly %(keyword)s')
)
where
name="%(name)s"
""" % args)

6
selling/utils.py

@ -113,8 +113,10 @@ def _get_basic_details(args, item_bean):
"description": item.description_html or item.description,
"reserved_warehouse": item.default_warehouse or args.warehouse or args.reserved_warehouse,
"warehouse": item.default_warehouse or args.warehouse,
"income_account": item.default_income_account or args.income_account,
"expense_account": item.purchase_account or args.expense_account,
"income_account": item.default_income_account or args.income_account \
or webnotes.conn.get_value("Company", args.company, "default_income_account"),
"expense_account": item.purchase_account or args.expense_account \
or webnotes.conn.get_value("Company", args.company, "default_expense_account"),
"cost_center": item.default_sales_cost_center or args.cost_center,
"qty": 1.0,
"adj_rate": 0.0,

2
setup/doctype/company/company.py

@ -191,6 +191,8 @@ class DocType:
def set_default_accounts(self):
accounts = {
"default_income_account": "Sales",
"default_expense_account": "Cost of Goods Sold",
"receivables_group": "Accounts Receivable",
"payables_group": "Accounts Payable",
"stock_received_but_not_billed": "Stock Received But Not Billed",

42
setup/doctype/company/company.txt

@ -2,7 +2,7 @@
{
"creation": "2013-04-10 08:35:39",
"docstatus": 0,
"modified": "2013-07-05 14:32:14",
"modified": "2013-07-08 17:34:21",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -89,15 +89,6 @@
"oldfieldtype": "Section Break",
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "default_currency",
"fieldtype": "Link",
"label": "Default Currency",
"options": "Currency",
"read_only": 0,
"reqd": 1
},
{
"depends_on": "eval:!doc.__islocal",
"doctype": "DocField",
@ -142,6 +133,28 @@
"options": "Account",
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "default_expense_account",
"fieldtype": "Link",
"label": "Default Expense Account",
"options": "Account"
},
{
"doctype": "DocField",
"fieldname": "default_income_account",
"fieldtype": "Link",
"label": "Default Income Account",
"options": "Account"
},
{
"doctype": "DocField",
"fieldname": "column_break0",
"fieldtype": "Column Break",
"oldfieldtype": "Column Break",
"read_only": 0,
"width": "50%"
},
{
"depends_on": "eval:!doc.__islocal",
"doctype": "DocField",
@ -153,11 +166,12 @@
},
{
"doctype": "DocField",
"fieldname": "column_break0",
"fieldtype": "Column Break",
"oldfieldtype": "Column Break",
"fieldname": "default_currency",
"fieldtype": "Link",
"label": "Default Currency",
"options": "Currency",
"read_only": 0,
"width": "50%"
"reqd": 1
},
{
"depends_on": "eval:!doc.__islocal",

5
stock/doctype/delivery_note/delivery_note.py

@ -369,7 +369,7 @@ class DocType(SellingController):
@webnotes.whitelist()
def make_sales_invoice(source_name, target_doclist=None):
def update_item(obj, target, source_parent):
target.export_amount = flt(obj.amount) - flt(obj.billed_amt)
target.export_amount = flt(obj.amount)
target.amount = target.export_amount / flt(source_parent.conversion_rate)
target.qty = obj.basic_rate and target.amount / flt(obj.basic_rate) or obj.qty
@ -393,8 +393,7 @@ def make_sales_invoice(source_name, target_doclist=None):
"prevdoc_docname": "sales_order",
"serial_no": "serial_no"
},
"postprocess": update_item,
"condition": lambda doc: doc.amount==0 or doc.billed_amt < doc.export_amount
"postprocess": update_item
},
"Sales Taxes and Charges": {
"doctype": "Sales Taxes and Charges",

29
stock/doctype/delivery_note/delivery_note.txt

@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:09",
"docstatus": 0,
"modified": "2013-07-08 16:34:21",
"modified": "2013-07-08 17:46:45",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -899,33 +899,6 @@
"search_index": 1,
"width": "150px"
},
{
"depends_on": "eval:!doc.__islocal",
"description": "% of materials billed against this Delivery Note",
"doctype": "DocField",
"fieldname": "per_billed",
"fieldtype": "Percent",
"in_filter": 1,
"in_list_view": 1,
"label": "% Amount Billed",
"no_copy": 1,
"oldfieldname": "per_billed",
"oldfieldtype": "Currency",
"print_hide": 1,
"read_only": 1,
"search_index": 1
},
{
"doctype": "DocField",
"fieldname": "billing_status",
"fieldtype": "Select",
"hidden": 1,
"label": "Billing Status",
"no_copy": 1,
"options": "\nNot Billed\nPartly Billed\nFully Billed",
"print_hide": 1,
"read_only": 0
},
{
"depends_on": "eval:!doc.__islocal",
"description": "% of materials delivered against this Delivery Note",

14
stock/doctype/delivery_note_item/delivery_note_item.txt

@ -2,7 +2,7 @@
{
"creation": "2013-04-22 13:15:44",
"docstatus": 0,
"modified": "2013-05-22 12:15:32",
"modified": "2013-07-08 17:46:21",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -308,18 +308,6 @@
"read_only": 1,
"width": "150px"
},
{
"doctype": "DocField",
"fieldname": "billed_amt",
"fieldtype": "Currency",
"label": "Billed Amt",
"no_copy": 1,
"options": "currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"width": "100px"
},
{
"doctype": "DocField",
"fieldname": "installed_qty",

76
stock/doctype/purchase_receipt/purchase_receipt.js

@ -35,6 +35,22 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
cur_frm.add_custom_button('Send SMS', cur_frm.cscript['Send SMS']);
}
cur_frm.add_custom_button(wn._('From Purchase Order'),
function() {
wn.model.map_current_doc({
method: "buying.doctype.purchase_order.purchase_order.make_purchase_receipt",
source_doctype: "Purchase Order",
get_query_filters: {
supplier: cur_frm.doc.supplier || undefined,
docstatus: 1,
status: ["!=", "Stopped"],
per_received: ["<", 99.99],
company: cur_frm.doc.company
}
})
});
if(wn.boot.control_panel.country == 'India') {
unhide_field(['challan_no', 'challan_date']);
}
@ -85,14 +101,11 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
source_name: cur_frm.doc.name
})
},
pull_purchase_order_details: function() {
wn.model.map_current_doc({
method: "buying.doctype.purchase_order.purchase_order.make_purchase_receipt",
source_name: cur_frm.doc.purchase_order_no,
})
}
tc_name: function() {
this.get_terms();
},
});
// for backward compatibility: combine new and previous states
@ -146,57 +159,10 @@ cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn)
return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
}
cur_frm.fields_dict['purchase_order_no'].get_query = function(doc) {
if (doc.supplier)
return 'SELECT DISTINCT `tabPurchase Order`.`name` FROM `tabPurchase Order` WHERE `tabPurchase Order`.`supplier` = "' +doc.supplier + '" and`tabPurchase Order`.`docstatus` = 1 and `tabPurchase Order`.`status` != "Stopped" and ifnull(`tabPurchase Order`.`per_received`, 0) < 99.99 and `tabPurchase Order`.`currency` = ifnull("' +doc.currency+ '","") and `tabPurchase Order`.company = "'+ doc.company +'" and `tabPurchase Order`.%(key)s LIKE "%s" ORDER BY `tabPurchase Order`.`name` DESC LIMIT 50';
else
return 'SELECT DISTINCT `tabPurchase Order`.`name` FROM `tabPurchase Order` WHERE `tabPurchase Order`.`docstatus` = 1 and `tabPurchase Order`.`company` = "'+ doc.company +'" and `tabPurchase Order`.`status` != "Stopped" and ifnull(`tabPurchase Order`.`per_received`, 0) < 99.99 and `tabPurchase Order`.%(key)s LIKE "%s" ORDER BY `tabPurchase Order`.`name` DESC LIMIT 50';
}
cur_frm.fields_dict.purchase_receipt_details.grid.get_field("qa_no").get_query = function(doc) {
return 'SELECT `tabQuality Inspection`.name FROM `tabQuality Inspection` WHERE `tabQuality Inspection`.docstatus = 1 AND `tabQuality Inspection`.%(key)s LIKE "%s"';
}
cur_frm.pformat.purchase_order_no = function(doc, cdt, cdn){
//function to make row of table
var make_row = function(title,val1, val2, bold){
var bstart = '<b>'; var bend = '</b>';
return '<tr><td style="width:39%;">'+(bold?bstart:'')+title+(bold?bend:'')+'</td>'
+'<td style="width:61%;text-align:left;">'+val1+(val2?' ('+dateutil.str_to_user(val2)+')':'')+'</td>'
+'</tr>'
}
out ='';
var cl = getchildren('Purchase Receipt Item',doc.name,'purchase_receipt_details');
// outer table
var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 50%"></td><td>';
// main table
out +='<table class="noborder" style="width:100%">';
// add rows
if(cl.length){
prevdoc_list = new Array();
for(var i=0;i<cl.length;i++){
if(cl[i].prevdoc_doctype == 'Purchase Order' && cl[i].prevdoc_docname && prevdoc_list.indexOf(cl[i].prevdoc_docname) == -1) {
prevdoc_list.push(cl[i].prevdoc_docname);
if(prevdoc_list.length ==1)
out += make_row(cl[i].prevdoc_doctype, cl[i].prevdoc_docname, cl[i].prevdoc_date,0);
else
out += make_row('', cl[i].prevdoc_docname, cl[i].prevdoc_date,0);
}
}
}
out +='</table></td></tr></table></div>';
return out;
}
cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
if(cint(wn.boot.notification_settings.purchase_receipt)) {
cur_frm.email_doc(wn.boot.notification_settings.purchase_receipt_message);

8
stock/doctype/purchase_receipt/purchase_receipt.py

@ -348,9 +348,10 @@ def make_purchase_invoice(source_name, target_doclist=None):
def update_item(obj, target, source_parent):
target.conversion_factor = 1
target.import_amount = flt(obj.import_amount) - flt(obj.billed_amt)
target.import_amount = flt(obj.import_amount)
target.amount = target.import_amount / flt(source_parent.conversion_rate)
target.qty = target.amount / flt(obj.purchase_rate)
if flt(obj.purchase_rate):
target.qty = target.amount / flt(obj.purchase_rate)
doclist = get_mapped_doclist("Purchase Receipt", source_name, {
"Purchase Receipt": {
@ -368,8 +369,7 @@ def make_purchase_invoice(source_name, target_doclist=None):
"prevdoc_docname": "purchase_order",
"purchase_rate": "rate"
},
"postprocess": update_item,
"condition": lambda doc: doc.amount==0 or doc.billed_amt < doc.import_amount
"postprocess": update_item
},
"Purchase Taxes and Charges": {
"doctype": "Purchase Taxes and Charges",

83
stock/doctype/purchase_receipt/purchase_receipt.txt

@ -2,7 +2,7 @@
{
"creation": "2013-05-21 16:16:39",
"docstatus": 0,
"modified": "2013-07-05 14:52:08",
"modified": "2013-07-08 17:46:13",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -32,6 +32,7 @@
"parent": "Purchase Receipt",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"report": 1
},
@ -241,32 +242,6 @@
"label": "Re-Calculate Values",
"oldfieldtype": "Button"
},
{
"doctype": "DocField",
"fieldname": "section_break_20",
"fieldtype": "Section Break"
},
{
"description": "You can make a purchase receipt from multiple purchase orders. Select purchase orders one by one and click on the button below.",
"doctype": "DocField",
"fieldname": "purchase_order_no",
"fieldtype": "Link",
"in_list_view": 0,
"label": "Purchase Order",
"no_copy": 1,
"oldfieldname": "purchase_order_no",
"oldfieldtype": "Link",
"options": "Purchase Order",
"print_hide": 0
},
{
"doctype": "DocField",
"fieldname": "pull_purchase_order_details",
"fieldtype": "Button",
"label": "Pull Purchase Order Details",
"oldfieldtype": "Button",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "currency_price_list",
@ -556,13 +531,6 @@
"options": "Terms and Conditions",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "get_terms",
"fieldtype": "Button",
"label": "Get Terms and Conditions",
"oldfieldtype": "Button"
},
{
"doctype": "DocField",
"fieldname": "terms",
@ -626,20 +594,6 @@
"search_index": 1,
"width": "150px"
},
{
"depends_on": "eval:!doc.__islocal",
"description": "% of materials billed against this Purchase Receipt",
"doctype": "DocField",
"fieldname": "per_billed",
"fieldtype": "Percent",
"in_list_view": 1,
"label": "% Billed",
"no_copy": 1,
"oldfieldname": "per_billed",
"oldfieldtype": "Currency",
"print_hide": 1,
"read_only": 1
},
{
"default": "No",
"description": "Select \"Yes\" for sub - contracting items",
@ -878,42 +832,20 @@
"print_hide": 1,
"read_only": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Material Manager",
"submit": 0,
"write": 0
},
{
"amend": 1,
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Material Manager",
"submit": 1,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Material User",
"submit": 0,
"write": 0
},
{
"amend": 1,
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Material User",
"submit": 1,
"write": 1
@ -923,24 +855,13 @@
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"permlevel": 0,
"role": "Purchase User",
"submit": 1,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"permlevel": 1,
"role": "Purchase User",
"submit": 0
},
{
"doctype": "DocPerm",
"match": "supplier",
"permlevel": 0,
"role": "Supplier"
}
]

12
stock/doctype/purchase_receipt_item/purchase_receipt_item.txt

@ -2,7 +2,7 @@
{
"creation": "2013-05-24 19:29:10",
"docstatus": 0,
"modified": "2013-07-08 13:52:28",
"modified": "2013-07-08 17:46:17",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -452,16 +452,6 @@
"search_index": 1,
"width": "150px"
},
{
"doctype": "DocField",
"fieldname": "billed_amt",
"fieldtype": "Currency",
"label": "Billed Amt",
"no_copy": 1,
"options": "currency",
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "valuation_rate",

Loading…
Cancel
Save