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(""" return frappe.db.sql("""
select b.cost_center, b.monthly_distribution, ba.account, ba.budget_amount select b.cost_center, b.monthly_distribution, ba.account, ba.budget_amount
from `tabBudget` b, `tabBudget Account` ba 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) """, (filters.fiscal_year, filters.company), as_dict=True)
#Get target distribution details of accounts of cost center #Get target distribution details of accounts of cost center
@ -86,6 +86,7 @@ def get_actual_details(cost_center, fiscal_year):
from `tabGL Entry` gl, `tabBudget Account` ba, `tabBudget` b from `tabGL Entry` gl, `tabBudget Account` ba, `tabBudget` b
where where
b.name = ba.parent b.name = ba.parent
and b.docstatus = 1
and ba.account=gl.account and ba.account=gl.account
and gl.fiscal_year=%s and gl.fiscal_year=%s
and b.cost_center=%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"]: for dt in ["Leave Application", "Leave Allocation", "Salary Slip"]:
frappe.db.sql("delete from `tab%s`" % dt) frappe.db.sql("delete from `tab%s`" % dt)
make_allocation_record(leave_type="_Test Leave Type LWP")
self.make_holiday_list() self.make_holiday_list()
frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Slip Test 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 \ from erpnext.manufacturing.doctype.production_order.production_order \
import make_stock_entry, ItemHasVariantError import make_stock_entry, ItemHasVariantError
from erpnext.stock.doctype.stock_entry import test_stock_entry 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.stock.utils import get_bin
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
class TestProductionOrder(unittest.TestCase): class TestProductionOrder(unittest.TestCase):
def setUp(self): def setUp(self):
@ -172,6 +174,28 @@ class TestProductionOrder(unittest.TestCase):
self.assertEqual(self.bin1_at_start.projected_qty, self.assertEqual(self.bin1_at_start.projected_qty,
cint(bin1_on_cancel.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): def test_reserved_qty_for_production_on_stock_entry(self):
test_stock_entry.make_stock_entry(item_code="_Test Item", test_stock_entry.make_stock_entry(item_code="_Test Item",
target= self.warehouse, qty=100, basic_rate=100) target= self.warehouse, qty=100, basic_rate=100)

View File

@ -473,7 +473,6 @@ class ProductionPlanningTool(Document):
material_request.update({"material_request_type": item_wrapper.default_material_request_type}) material_request.update({"material_request_type": item_wrapper.default_material_request_type})
for sales_order, requested_qty in items_to_be_requested[item].items(): for sales_order, requested_qty in items_to_be_requested[item].items():
if sales_order != 'No Sales Order':
material_request.append("items", { material_request.append("items", {
"doctype": "Material Request Item", "doctype": "Material Request Item",
"__islocal": 1, "__islocal": 1,

View File

@ -338,3 +338,4 @@ erpnext.patches.v7_1.set_total_amount_currency_in_je
finally:erpnext.patches.v7_0.update_timesheet_communications finally:erpnext.patches.v7_0.update_timesheet_communications
erpnext.patches.v7_0.update_status_of_zero_amount_sales_order erpnext.patches.v7_0.update_status_of_zero_amount_sales_order
erpnext.patches.v7_1.add_field_for_task_dependent 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 from frappe.utils import flt, add_days
import frappe.permissions import frappe.permissions
import unittest import unittest
from erpnext.stock.doctype.item.test_item import get_total_projected_qty
from erpnext.selling.doctype.sales_order.sales_order \ from erpnext.selling.doctype.sales_order.sales_order \
import make_material_request, make_delivery_note, make_sales_invoice, WarehouseRequired import make_material_request, make_delivery_note, make_sales_invoice, WarehouseRequired
@ -124,9 +125,17 @@ class TestSalesOrder(unittest.TestCase):
dn = create_dn_against_so(so.name, 15) dn = create_dn_against_so(so.name, 15)
self.assertEqual(get_reserved_qty(), existing_reserved_qty) 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() dn.cancel()
self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10) 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): def test_reserved_qty_for_over_delivery_via_sales_invoice(self):
# set over-delivery tolerance # set over-delivery tolerance
frappe.db.set_value('Item', "_Test Item", 'tolerance', 50) frappe.db.set_value('Item', "_Test Item", 'tolerance', 50)
@ -142,6 +151,10 @@ class TestSalesOrder(unittest.TestCase):
si.insert() si.insert()
si.submit() 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) self.assertEqual(get_reserved_qty(), existing_reserved_qty)
so.load_from_db() so.load_from_db()
@ -150,6 +163,9 @@ class TestSalesOrder(unittest.TestCase):
si.cancel() si.cancel()
self.assertEqual(get_reserved_qty(), existing_reserved_qty + 10) 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() so.load_from_db()
self.assertEqual(so.get("items")[0].delivered_qty, 0) 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"), existing_reserved_qty_item1)
self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"), existing_reserved_qty_item2) 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 # unclose so
so.load_from_db() so.load_from_db()
so.update_status('Draft') so.update_status('Draft')
@ -211,6 +231,10 @@ class TestSalesOrder(unittest.TestCase):
dn = create_dn_against_so(so.name, 15) 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"), existing_reserved_qty_item1)
self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"), self.assertEqual(get_reserved_qty("_Test Item Home Desktop 100"),
existing_reserved_qty_item2) existing_reserved_qty_item2)
@ -427,6 +451,13 @@ class TestSalesOrder(unittest.TestCase):
self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty_for_dn_item) 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): def test_reserved_qty_for_closing_so(self):
bin = frappe.get_all("Bin", filters={"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"}, bin = frappe.get_all("Bin", filters={"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"},
fields=["reserved_qty"]) fields=["reserved_qty"])

View File

@ -14,12 +14,12 @@ class Bin(Document):
self.stock_uom = frappe.db.get_value('Item', self.item_code, 'stock_uom') self.stock_uom = frappe.db.get_value('Item', self.item_code, 'stock_uom')
self.validate_mandatory() self.validate_mandatory()
self.set_projected_qty()
self.projected_qty = flt(self.actual_qty) + flt(self.ordered_qty) + \
flt(self.indented_qty) + flt(self.planned_qty) - flt(self.reserved_qty)
self.block_transactions_against_group_warehouse() self.block_transactions_against_group_warehouse()
def on_update(self):
update_item_projected_qty(self.item_code)
def validate_mandatory(self): def validate_mandatory(self):
qf = ['actual_qty', 'reserved_qty', 'ordered_qty', 'indented_qty'] qf = ['actual_qty', 'reserved_qty', 'ordered_qty', 'indented_qty']
for f in qf: for f in qf:
@ -72,9 +72,7 @@ class Bin(Document):
self.indented_qty = flt(self.indented_qty) + flt(args.get("indented_qty")) 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.planned_qty = flt(self.planned_qty) + flt(args.get("planned_qty"))
self.set_projected_qty()
self.save() self.save()
update_item_projected_qty(self.item_code)
def set_projected_qty(self): def set_projected_qty(self):
self.projected_qty = (flt(self.actual_qty) + flt(self.ordered_qty) 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.item_name = "_Test Variant Item-S"
variant.save() 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') test_records = frappe.get_test_records('Item')

View File

@ -2,7 +2,7 @@
{%- set compact_fields = doc.flags.compact_item_fields -%} {%- 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")-%} {% 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=""> <img class="print-item-image" src="{{ doc.image }}" alt="">
</div> </div>
{%- endif %} {%- endif %}