Fixed version conflict

This commit is contained in:
Nabin Hait 2016-10-19 16:49:36 +05:30
commit 0702fa2fc6
10 changed files with 113 additions and 27 deletions

View File

@ -64,7 +64,7 @@ def get_cost_center_target_details(filters):
return frappe.db.sql("""
select b.cost_center, b.monthly_distribution, ba.account, ba.budget_amount
from `tabBudget` b, `tabBudget Account` ba
where b.name=ba.parent and b.fiscal_year=%s and b.company=%s
where b.name=ba.parent and b.docstatus = 1 and b.fiscal_year=%s and b.company=%s
""", (filters.fiscal_year, filters.company), as_dict=True)
#Get target distribution details of accounts of cost center
@ -84,8 +84,9 @@ def get_actual_details(cost_center, fiscal_year):
ac_details = frappe.db.sql("""select gl.account, gl.debit, gl.credit,
MONTHNAME(gl.posting_date) as month_name, b.cost_center
from `tabGL Entry` gl, `tabBudget Account` ba, `tabBudget` b
where
where
b.name = ba.parent
and b.docstatus = 1
and ba.account=gl.account
and gl.fiscal_year=%s
and b.cost_center=%s

View File

@ -17,8 +17,6 @@ class TestSalarySlip(unittest.TestCase):
for dt in ["Leave Application", "Leave Allocation", "Salary Slip"]:
frappe.db.sql("delete from `tab%s`" % dt)
make_allocation_record(leave_type="_Test Leave Type LWP")
self.make_holiday_list()
frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Slip Test Holiday List")

View File

@ -10,7 +10,9 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_per
from erpnext.manufacturing.doctype.production_order.production_order \
import make_stock_entry, ItemHasVariantError
from erpnext.stock.doctype.stock_entry import test_stock_entry
from erpnext.stock.doctype.item.test_item import get_total_projected_qty
from erpnext.stock.utils import get_bin
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
class TestProductionOrder(unittest.TestCase):
def setUp(self):
@ -172,6 +174,28 @@ class TestProductionOrder(unittest.TestCase):
self.assertEqual(self.bin1_at_start.projected_qty,
cint(bin1_on_cancel.projected_qty))
def test_projected_qty_for_production_and_sales_order(self):
before_production_order = get_bin(self.item, self.warehouse)
before_production_order.update_reserved_qty_for_production()
self.pro_order = make_prod_order_test_record(item="_Test FG Item", qty=2,
source_warehouse=self.warehouse)
after_production_order = get_bin(self.item, self.warehouse)
sales_order = make_sales_order(item = self.item, qty = 2)
after_sales_order = get_bin(self.item, self.warehouse)
self.assertEqual(cint(before_production_order.reserved_qty_for_production) + 2,
cint(after_sales_order.reserved_qty_for_production))
self.assertEqual(cint(before_production_order.projected_qty),
cint(after_sales_order.projected_qty) + 2)
total_projected_qty = get_total_projected_qty(self.item)
item_doc = frappe.get_doc('Item', self.item)
self.assertEqual(total_projected_qty, item_doc.total_projected_qty)
def test_reserved_qty_for_production_on_stock_entry(self):
test_stock_entry.make_stock_entry(item_code="_Test Item",
target= self.warehouse, qty=100, basic_rate=100)

View File

@ -473,21 +473,20 @@ class ProductionPlanningTool(Document):
material_request.update({"material_request_type": item_wrapper.default_material_request_type})
for sales_order, requested_qty in items_to_be_requested[item].items():
if sales_order != 'No Sales Order':
material_request.append("items", {
"doctype": "Material Request Item",
"__islocal": 1,
"item_code": item,
"item_name": item_wrapper.item_name,
"description": item_wrapper.description,
"uom": item_wrapper.stock_uom,
"item_group": item_wrapper.item_group,
"brand": item_wrapper.brand,
"qty": requested_qty,
"schedule_date": add_days(nowdate(), cint(item_wrapper.lead_time_days)),
"warehouse": self.purchase_request_for_warehouse,
"sales_order": sales_order if sales_order!="No Sales Order" else None
})
material_request.append("items", {
"doctype": "Material Request Item",
"__islocal": 1,
"item_code": item,
"item_name": item_wrapper.item_name,
"description": item_wrapper.description,
"uom": item_wrapper.stock_uom,
"item_group": item_wrapper.item_group,
"brand": item_wrapper.brand,
"qty": requested_qty,
"schedule_date": add_days(nowdate(), cint(item_wrapper.lead_time_days)),
"warehouse": self.purchase_request_for_warehouse,
"sales_order": sales_order if sales_order!="No Sales Order" else None
})
material_request.flags.ignore_permissions = 1
material_request.submit()

View File

@ -338,3 +338,4 @@ erpnext.patches.v7_1.set_total_amount_currency_in_je
finally:erpnext.patches.v7_0.update_timesheet_communications
erpnext.patches.v7_0.update_status_of_zero_amount_sales_order
erpnext.patches.v7_1.add_field_for_task_dependent
erpnext.patches.v7_0.repost_bin_qty_and_item_projected_qty

View File

@ -0,0 +1,28 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from erpnext.stock.doctype.bin.bin import update_item_projected_qty
def execute():
repost_bin_qty()
repost_item_projected_qty()
def repost_bin_qty():
for bin in frappe.db.sql(""" select name from `tabBin`
where (actual_qty + ordered_qty + indented_qty + planned_qty- reserved_qty - reserved_qty_for_production) != projected_qty """, as_dict=1):
bin_doc = frappe.get_doc('Bin', bin.name)
bin_doc.set_projected_qty()
bin_doc.db_set("projected_qty", bin_doc.projected_qty, update_modified = False)
def repost_item_projected_qty():
for data in frappe.db.sql(""" select
`tabBin`.item_code as item_code,
sum(`tabBin`.projected_qty) as projected_qty,
`tabItem`.total_projected_qty as total_projected_qty
from
`tabBin`, `tabItem`
where `tabBin`.item_code = `tabItem`.name
group by `tabBin`.item_code having projected_qty <> total_projected_qty """, as_dict=1):
update_item_projected_qty(data.item_code)

View File

@ -5,6 +5,7 @@ import frappe
from frappe.utils import flt, add_days
import frappe.permissions
import unittest
from erpnext.stock.doctype.item.test_item import get_total_projected_qty
from erpnext.selling.doctype.sales_order.sales_order \
import make_material_request, make_delivery_note, make_sales_invoice, WarehouseRequired
@ -124,8 +125,16 @@ class TestSalesOrder(unittest.TestCase):
dn = create_dn_against_so(so.name, 15)
self.assertEqual(get_reserved_qty(), existing_reserved_qty)
total_projected_qty = get_total_projected_qty('_Test Item')
item_doc_before_cancel = frappe.get_doc('Item', '_Test Item')
self.assertEqual(total_projected_qty, item_doc_before_cancel.total_projected_qty)
dn.cancel()
self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10)
total_projected_qty = get_total_projected_qty('_Test Item')
item_doc_after_cancel = frappe.get_doc('Item', '_Test Item')
self.assertEqual(total_projected_qty, item_doc_after_cancel.total_projected_qty)
def test_reserved_qty_for_over_delivery_via_sales_invoice(self):
# set over-delivery tolerance
@ -141,6 +150,10 @@ class TestSalesOrder(unittest.TestCase):
si.get("items")[0].qty = 12
si.insert()
si.submit()
total_projected_qty = get_total_projected_qty('_Test Item')
item_doc = frappe.get_doc('Item', '_Test Item')
self.assertEqual(total_projected_qty, item_doc.total_projected_qty)
self.assertEqual(get_reserved_qty(), existing_reserved_qty)
@ -150,6 +163,9 @@ class TestSalesOrder(unittest.TestCase):
si.cancel()
self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10)
total_projected_qty = get_total_projected_qty('_Test Item')
item_doc = frappe.get_doc('Item', '_Test Item')
self.assertEqual(total_projected_qty, item_doc.total_projected_qty)
so.load_from_db()
self.assertEqual(so.get("items")[0].delivered_qty, 0)
@ -178,6 +194,10 @@ class TestSalesOrder(unittest.TestCase):
self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1)
self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"), existing_reserved_qty_item2)
total_projected_qty = get_total_projected_qty('_Test Item')
item_doc = frappe.get_doc('Item', '_Test Item')
self.assertEqual(total_projected_qty, item_doc.total_projected_qty)
# unclose so
so.load_from_db()
so.update_status('Draft')
@ -211,6 +231,10 @@ class TestSalesOrder(unittest.TestCase):
dn = create_dn_against_so(so.name, 15)
total_projected_qty = get_total_projected_qty('_Test Item')
item_doc = frappe.get_doc('Item', '_Test Item')
self.assertEqual(total_projected_qty, item_doc.total_projected_qty)
self.assertEqual(get_reserved_qty("_Test Item"), existing_reserved_qty_item1)
self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"),
existing_reserved_qty_item2)
@ -427,6 +451,13 @@ class TestSalesOrder(unittest.TestCase):
self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty_for_dn_item)
def test_total_projected_qty_against_sales_order(self):
so = make_sales_order(item = '_Test Item')
total_projected_qty = get_total_projected_qty('_Test Item')
item_doc = frappe.get_doc('Item', '_Test Item')
self.assertEqual(total_projected_qty, item_doc.total_projected_qty)
def test_reserved_qty_for_closing_so(self):
bin = frappe.get_all("Bin", filters={"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"},
fields=["reserved_qty"])

View File

@ -14,18 +14,18 @@ class Bin(Document):
self.stock_uom = frappe.db.get_value('Item', self.item_code, 'stock_uom')
self.validate_mandatory()
self.projected_qty = flt(self.actual_qty) + flt(self.ordered_qty) + \
flt(self.indented_qty) + flt(self.planned_qty) - flt(self.reserved_qty)
self.set_projected_qty()
self.block_transactions_against_group_warehouse()
def on_update(self):
update_item_projected_qty(self.item_code)
def validate_mandatory(self):
qf = ['actual_qty', 'reserved_qty', 'ordered_qty', 'indented_qty']
for f in qf:
if (not getattr(self, f, None)) or (not self.get(f)):
self.set(f, 0.0)
def block_transactions_against_group_warehouse(self):
from erpnext.stock.utils import is_group_warehouse
is_group_warehouse(self.warehouse)
@ -72,9 +72,7 @@ class Bin(Document):
self.indented_qty = flt(self.indented_qty) + flt(args.get("indented_qty"))
self.planned_qty = flt(self.planned_qty) + flt(args.get("planned_qty"))
self.set_projected_qty()
self.save()
update_item_projected_qty(self.item_code)
def set_projected_qty(self):
self.projected_qty = (flt(self.actual_qty) + flt(self.ordered_qty)

View File

@ -177,4 +177,10 @@ def make_item_variant():
variant.item_name = "_Test Variant Item-S"
variant.save()
def get_total_projected_qty(item):
total_qty = frappe.db.sql(""" select sum(projected_qty) as projected_qty from tabBin
where item_code = %(item)s""", {'item': item}, as_dict=1)
return total_qty[0].projected_qty if total_qty else 0.0
test_records = frappe.get_test_records('Item')

View File

@ -2,7 +2,7 @@
{%- set compact_fields = doc.flags.compact_item_fields -%}
{% if doc.in_format_data("image") and doc.get("image") and not doc.is_print_hide("image")-%}
<div class="pull-left" style="width: 20%; margin-right: 10px;">
<div class="pull-left" style="max-width: 40%; margin-right: 10px;">
<img class="print-item-image" src="{{ doc.image }}" alt="">
</div>
{%- endif %}