Merge pull request #1945 from anandpdoshi/anand-july-16

Fixes in Stock Entry and test cases
This commit is contained in:
Rushabh Mehta 2014-07-16 17:04:18 +05:30
commit 2e21e25613
3 changed files with 305 additions and 303 deletions

View File

@ -1,385 +1,385 @@
[ [
{ {
"company": "_Test Company", "company": "_Test Company",
"conversion_rate": 1.0, "conversion_rate": 1.0,
"currency": "INR", "currency": "INR",
"customer": "_Test Customer", "customer": "_Test Customer",
"customer_name": "_Test Customer", "customer_name": "_Test Customer",
"debit_to": "_Test Customer - _TC", "debit_to": "_Test Customer - _TC",
"doctype": "Sales Invoice", "doctype": "Sales Invoice",
"due_date": "2013-01-23", "due_date": "2013-01-23",
"entries": [ "entries": [
{ {
"amount": 500.0, "amount": 500.0,
"base_amount": 500.0, "base_amount": 500.0,
"base_rate": 500.0, "base_rate": 500.0,
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "138-CMS Shoe", "description": "138-CMS Shoe",
"doctype": "Sales Invoice Item", "doctype": "Sales Invoice Item",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"item_name": "138-CMS Shoe", "item_name": "138-CMS Shoe",
"parentfield": "entries", "parentfield": "entries",
"qty": 1.0, "qty": 1.0,
"rate": 500.0 "rate": 500.0
} }
], ],
"fiscal_year": "_Test Fiscal Year 2013", "fiscal_year": "_Test Fiscal Year 2013",
"grand_total": 561.8, "grand_total": 561.8,
"grand_total_export": 561.8, "grand_total_export": 561.8,
"is_pos": 0, "is_pos": 0,
"naming_series": "_T-Sales Invoice-", "naming_series": "_T-Sales Invoice-",
"net_total": 500.0, "net_total": 500.0,
"other_charges": [ "other_charges": [
{ {
"account_head": "_Test Account VAT - _TC", "account_head": "_Test Account VAT - _TC",
"charge_type": "On Net Total", "charge_type": "On Net Total",
"description": "VAT", "description": "VAT",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 6 "rate": 6
}, },
{ {
"account_head": "_Test Account Service Tax - _TC", "account_head": "_Test Account Service Tax - _TC",
"charge_type": "On Net Total", "charge_type": "On Net Total",
"description": "Service Tax", "description": "Service Tax",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 6.36 "rate": 6.36
} }
], ],
"plc_conversion_rate": 1.0, "plc_conversion_rate": 1.0,
"posting_date": "2013-01-23", "posting_date": "2013-01-23",
"price_list_currency": "INR", "price_list_currency": "INR",
"sales_team": [ "sales_team": [
{ {
"allocated_percentage": 65.5, "allocated_percentage": 65.5,
"doctype": "Sales Team", "doctype": "Sales Team",
"parentfield": "sales_team", "parentfield": "sales_team",
"sales_person": "_Test Sales Person 1" "sales_person": "_Test Sales Person 1"
}, },
{ {
"allocated_percentage": 34.5, "allocated_percentage": 34.5,
"doctype": "Sales Team", "doctype": "Sales Team",
"parentfield": "sales_team", "parentfield": "sales_team",
"sales_person": "_Test Sales Person 2" "sales_person": "_Test Sales Person 2"
} }
], ],
"selling_price_list": "_Test Price List", "selling_price_list": "_Test Price List",
"territory": "_Test Territory" "territory": "_Test Territory"
}, },
{ {
"company": "_Test Company", "company": "_Test Company",
"conversion_rate": 1.0, "conversion_rate": 1.0,
"currency": "INR", "currency": "INR",
"customer": "_Test Customer", "customer": "_Test Customer",
"customer_name": "_Test Customer", "customer_name": "_Test Customer",
"debit_to": "_Test Customer - _TC", "debit_to": "_Test Customer - _TC",
"doctype": "Sales Invoice", "doctype": "Sales Invoice",
"due_date": "2013-01-23", "due_date": "2013-03-07",
"entries": [ "entries": [
{ {
"amount": 500.0, "amount": 500.0,
"base_amount": 500.0, "base_amount": 500.0,
"base_rate": 500.0, "base_rate": 500.0,
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "_Test Item", "description": "_Test Item",
"doctype": "Sales Invoice Item", "doctype": "Sales Invoice Item",
"expense_account": "_Test Account Cost for Goods Sold - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"item_code": "_Test Item", "item_code": "_Test Item",
"item_name": "_Test Item", "item_name": "_Test Item",
"parentfield": "entries", "parentfield": "entries",
"price_list_rate": 500.0, "price_list_rate": 500.0,
"qty": 1.0 "qty": 1.0
} }
], ],
"fiscal_year": "_Test Fiscal Year 2013", "fiscal_year": "_Test Fiscal Year 2013",
"grand_total": 630.0, "grand_total": 630.0,
"grand_total_export": 630.0, "grand_total_export": 630.0,
"is_pos": 0, "is_pos": 0,
"naming_series": "_T-Sales Invoice-", "naming_series": "_T-Sales Invoice-",
"net_total": 500.0, "net_total": 500.0,
"other_charges": [ "other_charges": [
{ {
"account_head": "_Test Account VAT - _TC", "account_head": "_Test Account VAT - _TC",
"charge_type": "On Net Total", "charge_type": "On Net Total",
"description": "VAT", "description": "VAT",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 16 "rate": 16
}, },
{ {
"account_head": "_Test Account Service Tax - _TC", "account_head": "_Test Account Service Tax - _TC",
"charge_type": "On Net Total", "charge_type": "On Net Total",
"description": "Service Tax", "description": "Service Tax",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 10 "rate": 10
} }
], ],
"plc_conversion_rate": 1.0, "plc_conversion_rate": 1.0,
"posting_date": "2013-03-07", "posting_date": "2013-03-07",
"price_list_currency": "INR", "price_list_currency": "INR",
"selling_price_list": "_Test Price List", "selling_price_list": "_Test Price List",
"territory": "_Test Territory" "territory": "_Test Territory"
}, },
{ {
"company": "_Test Company", "company": "_Test Company",
"conversion_rate": 1.0, "conversion_rate": 1.0,
"currency": "INR", "currency": "INR",
"customer": "_Test Customer", "customer": "_Test Customer",
"customer_name": "_Test Customer", "customer_name": "_Test Customer",
"debit_to": "_Test Customer - _TC", "debit_to": "_Test Customer - _TC",
"doctype": "Sales Invoice", "doctype": "Sales Invoice",
"due_date": "2013-01-23", "due_date": "2013-01-23",
"entries": [ "entries": [
{ {
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"doctype": "Sales Invoice Item", "doctype": "Sales Invoice Item",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"item_code": "_Test Item Home Desktop 100", "item_code": "_Test Item Home Desktop 100",
"item_name": "_Test Item Home Desktop 100", "item_name": "_Test Item Home Desktop 100",
"item_tax_rate": "{\"_Test Account Excise Duty - _TC\": 10}", "item_tax_rate": "{\"_Test Account Excise Duty - _TC\": 10}",
"parentfield": "entries", "parentfield": "entries",
"price_list_rate": 50, "price_list_rate": 50,
"qty": 10, "qty": 10,
"rate": 50, "rate": 50,
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"doctype": "Sales Invoice Item", "doctype": "Sales Invoice Item",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"item_code": "_Test Item Home Desktop 200", "item_code": "_Test Item Home Desktop 200",
"item_name": "_Test Item Home Desktop 200", "item_name": "_Test Item Home Desktop 200",
"parentfield": "entries", "parentfield": "entries",
"price_list_rate": 150, "price_list_rate": 150,
"qty": 5, "qty": 5,
"rate": 150, "rate": 150,
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
} }
], ],
"fiscal_year": "_Test Fiscal Year 2013", "fiscal_year": "_Test Fiscal Year 2013",
"grand_total_export": 0, "grand_total_export": 0,
"is_pos": 0, "is_pos": 0,
"naming_series": "_T-Sales Invoice-", "naming_series": "_T-Sales Invoice-",
"other_charges": [ "other_charges": [
{ {
"account_head": "_Test Account Shipping Charges - _TC", "account_head": "_Test Account Shipping Charges - _TC",
"charge_type": "Actual", "charge_type": "Actual",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "Shipping Charges", "description": "Shipping Charges",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 100 "rate": 100
}, },
{ {
"account_head": "_Test Account Customs Duty - _TC", "account_head": "_Test Account Customs Duty - _TC",
"charge_type": "On Net Total", "charge_type": "On Net Total",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "Customs Duty", "description": "Customs Duty",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 10 "rate": 10
}, },
{ {
"account_head": "_Test Account Excise Duty - _TC", "account_head": "_Test Account Excise Duty - _TC",
"charge_type": "On Net Total", "charge_type": "On Net Total",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "Excise Duty", "description": "Excise Duty",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 12 "rate": 12
}, },
{ {
"account_head": "_Test Account Education Cess - _TC", "account_head": "_Test Account Education Cess - _TC",
"charge_type": "On Previous Row Amount", "charge_type": "On Previous Row Amount",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "Education Cess", "description": "Education Cess",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 2, "rate": 2,
"row_id": 3 "row_id": 3
}, },
{ {
"account_head": "_Test Account S&H Education Cess - _TC", "account_head": "_Test Account S&H Education Cess - _TC",
"charge_type": "On Previous Row Amount", "charge_type": "On Previous Row Amount",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "S&H Education Cess", "description": "S&H Education Cess",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 1, "rate": 1,
"row_id": 3 "row_id": 3
}, },
{ {
"account_head": "_Test Account CST - _TC", "account_head": "_Test Account CST - _TC",
"charge_type": "On Previous Row Total", "charge_type": "On Previous Row Total",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "CST", "description": "CST",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 2, "rate": 2,
"row_id": 5 "row_id": 5
}, },
{ {
"account_head": "_Test Account VAT - _TC", "account_head": "_Test Account VAT - _TC",
"charge_type": "On Net Total", "charge_type": "On Net Total",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "VAT", "description": "VAT",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 12.5 "rate": 12.5
}, },
{ {
"account_head": "_Test Account Discount - _TC", "account_head": "_Test Account Discount - _TC",
"charge_type": "On Previous Row Total", "charge_type": "On Previous Row Total",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "Discount", "description": "Discount",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": -10, "rate": -10,
"row_id": 7 "row_id": 7
} }
], ],
"plc_conversion_rate": 1.0, "plc_conversion_rate": 1.0,
"posting_date": "2013-01-23", "posting_date": "2013-01-23",
"price_list_currency": "INR", "price_list_currency": "INR",
"selling_price_list": "_Test Price List", "selling_price_list": "_Test Price List",
"territory": "_Test Territory" "territory": "_Test Territory"
}, },
{ {
"company": "_Test Company", "company": "_Test Company",
"conversion_rate": 1.0, "conversion_rate": 1.0,
"currency": "INR", "currency": "INR",
"customer": "_Test Customer", "customer": "_Test Customer",
"customer_name": "_Test Customer", "customer_name": "_Test Customer",
"debit_to": "_Test Customer - _TC", "debit_to": "_Test Customer - _TC",
"doctype": "Sales Invoice", "doctype": "Sales Invoice",
"due_date": "2013-01-23", "due_date": "2013-01-23",
"entries": [ "entries": [
{ {
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"doctype": "Sales Invoice Item", "doctype": "Sales Invoice Item",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"item_code": "_Test Item Home Desktop 100", "item_code": "_Test Item Home Desktop 100",
"item_name": "_Test Item Home Desktop 100", "item_name": "_Test Item Home Desktop 100",
"item_tax_rate": "{\"_Test Account Excise Duty - _TC\": 10}", "item_tax_rate": "{\"_Test Account Excise Duty - _TC\": 10}",
"parentfield": "entries", "parentfield": "entries",
"price_list_rate": 62.5, "price_list_rate": 62.5,
"qty": 10, "qty": 10,
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}, },
{ {
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"doctype": "Sales Invoice Item", "doctype": "Sales Invoice Item",
"income_account": "Sales - _TC", "income_account": "Sales - _TC",
"item_code": "_Test Item Home Desktop 200", "item_code": "_Test Item Home Desktop 200",
"item_name": "_Test Item Home Desktop 200", "item_name": "_Test Item Home Desktop 200",
"parentfield": "entries", "parentfield": "entries",
"price_list_rate": 190.66, "price_list_rate": 190.66,
"qty": 5, "qty": 5,
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
} }
], ],
"fiscal_year": "_Test Fiscal Year 2013", "fiscal_year": "_Test Fiscal Year 2013",
"grand_total_export": 0, "grand_total_export": 0,
"is_pos": 0, "is_pos": 0,
"naming_series": "_T-Sales Invoice-", "naming_series": "_T-Sales Invoice-",
"other_charges": [ "other_charges": [
{ {
"account_head": "_Test Account Excise Duty - _TC", "account_head": "_Test Account Excise Duty - _TC",
"charge_type": "On Net Total", "charge_type": "On Net Total",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "Excise Duty", "description": "Excise Duty",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"idx": 1, "idx": 1,
"included_in_print_rate": 1, "included_in_print_rate": 1,
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 12 "rate": 12
}, },
{ {
"account_head": "_Test Account Education Cess - _TC", "account_head": "_Test Account Education Cess - _TC",
"charge_type": "On Previous Row Amount", "charge_type": "On Previous Row Amount",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "Education Cess", "description": "Education Cess",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"idx": 2, "idx": 2,
"included_in_print_rate": 1, "included_in_print_rate": 1,
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 2, "rate": 2,
"row_id": 1 "row_id": 1
}, },
{ {
"account_head": "_Test Account S&H Education Cess - _TC", "account_head": "_Test Account S&H Education Cess - _TC",
"charge_type": "On Previous Row Amount", "charge_type": "On Previous Row Amount",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "S&H Education Cess", "description": "S&H Education Cess",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"idx": 3, "idx": 3,
"included_in_print_rate": 1, "included_in_print_rate": 1,
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 1, "rate": 1,
"row_id": 1 "row_id": 1
}, },
{ {
"account_head": "_Test Account CST - _TC", "account_head": "_Test Account CST - _TC",
"charge_type": "On Previous Row Total", "charge_type": "On Previous Row Total",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "CST", "description": "CST",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"idx": 4, "idx": 4,
"included_in_print_rate": 1, "included_in_print_rate": 1,
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 2, "rate": 2,
"row_id": 3 "row_id": 3
}, },
{ {
"account_head": "_Test Account VAT - _TC", "account_head": "_Test Account VAT - _TC",
"charge_type": "On Net Total", "charge_type": "On Net Total",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "VAT", "description": "VAT",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"idx": 5, "idx": 5,
"included_in_print_rate": 1, "included_in_print_rate": 1,
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 12.5 "rate": 12.5
}, },
{ {
"account_head": "_Test Account Customs Duty - _TC", "account_head": "_Test Account Customs Duty - _TC",
"charge_type": "On Net Total", "charge_type": "On Net Total",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "Customs Duty", "description": "Customs Duty",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"idx": 6, "idx": 6,
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 10 "rate": 10
}, },
{ {
"account_head": "_Test Account Shipping Charges - _TC", "account_head": "_Test Account Shipping Charges - _TC",
"charge_type": "Actual", "charge_type": "Actual",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "Shipping Charges", "description": "Shipping Charges",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"idx": 7, "idx": 7,
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": 100 "rate": 100
}, },
{ {
"account_head": "_Test Account Discount - _TC", "account_head": "_Test Account Discount - _TC",
"charge_type": "On Previous Row Total", "charge_type": "On Previous Row Total",
"cost_center": "_Test Cost Center - _TC", "cost_center": "_Test Cost Center - _TC",
"description": "Discount", "description": "Discount",
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"idx": 8, "idx": 8,
"parentfield": "other_charges", "parentfield": "other_charges",
"rate": -10, "rate": -10,
"row_id": 7 "row_id": 7
} }
], ],
"plc_conversion_rate": 1.0, "plc_conversion_rate": 1.0,
"posting_date": "2013-01-23", "posting_date": "2013-01-23",
"price_list_currency": "INR", "price_list_currency": "INR",
"selling_price_list": "_Test Price List", "selling_price_list": "_Test Price List",
"territory": "_Test Territory" "territory": "_Test Territory"
} }
] ]

View File

@ -674,6 +674,7 @@ class TestSalesInvoice(unittest.TestCase):
"notification_email_address": "test@example.com, test1@example.com, test2@example.com", "notification_email_address": "test@example.com, test1@example.com, test2@example.com",
"repeat_on_day_of_month": getdate(today).day, "repeat_on_day_of_month": getdate(today).day,
"posting_date": today, "posting_date": today,
"due_date": None,
"fiscal_year": get_fiscal_year(today)[0], "fiscal_year": get_fiscal_year(today)[0],
"invoice_period_from_date": get_first_day(today), "invoice_period_from_date": get_first_day(today),
"invoice_period_to_date": get_last_day(today) "invoice_period_to_date": get_last_day(today)

View File

@ -204,7 +204,7 @@ class StockEntry(StockController):
if not self.posting_date or not self.posting_time: if not self.posting_date or not self.posting_time:
frappe.throw(_("Posting date and posting time is mandatory")) frappe.throw(_("Posting date and posting time is mandatory"))
allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock") allow_negative_stock = cint(frappe.db.get_default("allow_negative_stock"))
for d in self.get('mtn_details'): for d in self.get('mtn_details'):
args = frappe._dict({ args = frappe._dict({
@ -219,7 +219,8 @@ class StockEntry(StockController):
# get actual stock at source warehouse # get actual stock at source warehouse
d.actual_qty = get_previous_sle(args).get("qty_after_transaction") or 0 d.actual_qty = get_previous_sle(args).get("qty_after_transaction") or 0
if d.s_warehouse and not allow_negative_stock and d.actual_qty <= d.transfer_qty: # validate qty during submit
if d.docstatus==1 and d.s_warehouse and not allow_negative_stock and d.actual_qty < d.transfer_qty:
frappe.throw(_("""Row {0}: Qty not avalable in warehouse {1} on {2} {3}. frappe.throw(_("""Row {0}: Qty not avalable in warehouse {1} on {2} {3}.
Available Qty: {4}, Transfer Qty: {5}""").format(d.idx, d.s_warehouse, Available Qty: {4}, Transfer Qty: {5}""").format(d.idx, d.s_warehouse,
self.posting_date, self.posting_time, d.actual_qty, d.transfer_qty)) self.posting_date, self.posting_time, d.actual_qty, d.transfer_qty))