Merge branch 'develop' into fix-asset-warehouse-validation

This commit is contained in:
Saqib Ansari 2022-03-30 14:58:49 +05:30 committed by GitHub
commit 03e6a6c699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 124 additions and 181 deletions

View File

@ -31,6 +31,7 @@ ignore =
E124, # closing bracket, irritating while writing QB code
E131, # continuation line unaligned for hanging indent
E123, # closing bracket does not match indentation of opening bracket's line
E101, # ensured by use of black
max-line-length = 200
exclude=.github/helper/semgrep_rules

View File

@ -1,117 +0,0 @@
name: UI
on:
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:
concurrency:
group: ui-develop-${{ github.event.number }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
name: UI Tests (Cypress)
services:
mysql:
image: mariadb:10.3
env:
MYSQL_ALLOW_EMPTY_PASSWORD: YES
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- name: Clone
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: actions/setup-node@v2
with:
node-version: 14
check-latest: true
- name: Add to Hosts
run: |
echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache cypress binary
uses: actions/cache@v2
with:
path: ~/.cache
key: ${{ runner.os }}-cypress-
restore-keys: |
${{ runner.os }}-cypress-
${{ runner.os }}-
- name: Install
run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
env:
DB: mariadb
TYPE: ui
- name: Site Setup
run: cd ~/frappe-bench/ && bench --site test_site execute erpnext.setup.utils.before_tests
- name: cypress pre-requisites
run: cd ~/frappe-bench/apps/frappe && yarn add cypress-file-upload@^5 @testing-library/cypress@^8 --no-lockfile
- name: Build Assets
run: cd ~/frappe-bench/ && bench build
env:
CI: Yes
- name: UI Tests
run: cd ~/frappe-bench/ && bench --site test_site run-ui-tests erpnext --headless
env:
CYPRESS_RECORD_KEY: 60a8e3bf-08f5-45b1-9269-2b207d7d30cd
- name: Show bench console if tests failed
if: ${{ failure() }}
run: cat ~/frappe-bench/bench_run_logs.txt

View File

@ -1025,7 +1025,7 @@ def get_bom_items_as_dict(
query = query.format(
table="BOM Scrap Item",
where_conditions="",
select_columns=", bom_item.idx, item.description, is_process_loss",
select_columns=", item.description, is_process_loss",
is_stock_item=is_stock_item,
qty_field="stock_qty",
)
@ -1038,7 +1038,7 @@ def get_bom_items_as_dict(
is_stock_item=is_stock_item,
qty_field="stock_qty" if fetch_qty_in_stock_uom else "qty",
select_columns=""", bom_item.uom, bom_item.conversion_factor, bom_item.source_warehouse,
bom_item.idx, bom_item.operation, bom_item.include_item_in_manufacturing, bom_item.sourced_by_supplier,
bom_item.operation, bom_item.include_item_in_manufacturing, bom_item.sourced_by_supplier,
bom_item.description, bom_item.base_rate as rate """,
)
items = frappe.db.sql(query, {"qty": qty, "bom": bom, "company": company}, as_dict=True)

View File

@ -1114,6 +1114,36 @@ class TestWorkOrder(FrappeTestCase):
except frappe.MandatoryError:
self.fail("Batch generation causing failing in Work Order")
@change_settings(
"Manufacturing Settings",
{"backflush_raw_materials_based_on": "Material Transferred for Manufacture"},
)
def test_manufacture_entry_mapped_idx_with_exploded_bom(self):
"""Test if WO containing BOM with partial exploded items and scrap items, maps idx correctly."""
test_stock_entry.make_stock_entry(
item_code="_Test Item",
target="_Test Warehouse - _TC",
basic_rate=5000.0,
qty=2,
)
test_stock_entry.make_stock_entry(
item_code="_Test Item Home Desktop 100",
target="_Test Warehouse - _TC",
basic_rate=1000.0,
qty=2,
)
wo_order = make_wo_order_test_record(
qty=1,
use_multi_level_bom=1,
skip_transfer=1,
)
ste_manu = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 1))
for index, row in enumerate(ste_manu.get("items"), start=1):
self.assertEqual(index, row.idx)
def update_job_card(job_card, jc_qty=None):
employee = frappe.db.get_value("Employee", {"status": "Active"}, "name")

View File

@ -147,6 +147,8 @@ class AdditionalSalary(Document):
@frappe.whitelist()
def get_additional_salaries(employee, start_date, end_date, component_type):
from frappe.query_builder import Criterion
comp_type = "Earning" if component_type == "earnings" else "Deduction"
additional_sal = frappe.qb.DocType("Additional Salary")
@ -170,8 +172,23 @@ def get_additional_salaries(employee, start_date, end_date, component_type):
& (additional_sal.type == comp_type)
)
.where(
additional_sal.payroll_date[start_date:end_date]
| ((additional_sal.from_date <= end_date) & (additional_sal.to_date >= end_date))
Criterion.any(
[
Criterion.all(
[ # is recurring and additional salary dates fall within the payroll period
additional_sal.is_recurring == 1,
additional_sal.from_date <= end_date,
additional_sal.to_date >= end_date,
]
),
Criterion.all(
[ # is not recurring and additional salary's payroll date falls within the payroll period
additional_sal.is_recurring == 0,
additional_sal.payroll_date[start_date:end_date],
]
),
]
)
)
.run(as_dict=True)
)

View File

@ -4,7 +4,8 @@
import unittest
import frappe
from frappe.utils import add_days, nowdate
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, add_months, nowdate
import erpnext
from erpnext.hr.doctype.employee.test_employee import make_employee
@ -16,19 +17,10 @@ from erpnext.payroll.doctype.salary_slip.test_salary_slip import (
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
class TestAdditionalSalary(unittest.TestCase):
class TestAdditionalSalary(FrappeTestCase):
def setUp(self):
setup_test()
def tearDown(self):
for dt in [
"Salary Slip",
"Additional Salary",
"Salary Structure Assignment",
"Salary Structure",
]:
frappe.db.sql("delete from `tab%s`" % dt)
def test_recurring_additional_salary(self):
amount = 0
salary_component = None
@ -46,19 +38,66 @@ class TestAdditionalSalary(unittest.TestCase):
if earning.salary_component == "Recurring Salary Component":
amount = earning.amount
salary_component = earning.salary_component
break
self.assertEqual(amount, add_sal.amount)
self.assertEqual(salary_component, add_sal.salary_component)
def test_non_recurring_additional_salary(self):
amount = 0
salary_component = None
date = nowdate()
def get_additional_salary(emp_id):
emp_id = make_employee("test_additional@salary.com")
frappe.db.set_value("Employee", emp_id, "relieving_date", add_days(date, 1800))
salary_structure = make_salary_structure(
"Test Salary Structure Additional Salary", "Monthly", employee=emp_id
)
add_sal = get_additional_salary(emp_id, recurring=False, payroll_date=date)
ss = make_employee_salary_slip(
"test_additional@salary.com", "Monthly", salary_structure=salary_structure.name
)
amount, salary_component = None, None
for earning in ss.earnings:
if earning.salary_component == "Recurring Salary Component":
amount = earning.amount
salary_component = earning.salary_component
break
self.assertEqual(amount, add_sal.amount)
self.assertEqual(salary_component, add_sal.salary_component)
# should not show up in next months
ss.posting_date = add_months(date, 1)
ss.start_date = ss.end_date = None
ss.earnings = []
ss.deductions = []
ss.save()
amount, salary_component = None, None
for earning in ss.earnings:
if earning.salary_component == "Recurring Salary Component":
amount = earning.amount
salary_component = earning.salary_component
break
self.assertIsNone(amount)
self.assertIsNone(salary_component)
def get_additional_salary(emp_id, recurring=True, payroll_date=None):
create_salary_component("Recurring Salary Component")
add_sal = frappe.new_doc("Additional Salary")
add_sal.employee = emp_id
add_sal.salary_component = "Recurring Salary Component"
add_sal.is_recurring = 1
add_sal.is_recurring = 1 if recurring else 0
add_sal.from_date = add_days(nowdate(), -50)
add_sal.to_date = add_days(nowdate(), 180)
add_sal.payroll_date = payroll_date
add_sal.amount = 5000
add_sal.currency = erpnext.get_default_currency()
add_sal.save()

View File

@ -1,4 +1,4 @@
<div>
<div class="stock-levels">
<div class="result">
</div>
<div class="more hidden" style="padding: 15px;">

View File

@ -280,8 +280,11 @@ class DeliveryNote(SellingController):
)
if bypass_credit_limit_check_at_sales_order:
validate_against_credit_limit = True
extra_amount = self.base_grand_total
for d in self.get("items"):
if not d.against_sales_invoice:
validate_against_credit_limit = True
extra_amount = self.base_grand_total
break
else:
for d in self.get("items"):
if not (d.against_sales_order or d.against_sales_invoice):

View File

@ -225,12 +225,16 @@ class StockEntry(StockController):
def set_transfer_qty(self):
for item in self.get("items"):
if not flt(item.qty):
frappe.throw(_("Row {0}: Qty is mandatory").format(item.idx))
frappe.throw(_("Row {0}: Qty is mandatory").format(item.idx), title=_("Zero quantity"))
if not flt(item.conversion_factor):
frappe.throw(_("Row {0}: UOM Conversion Factor is mandatory").format(item.idx))
item.transfer_qty = flt(
flt(item.qty) * flt(item.conversion_factor), self.precision("transfer_qty", item)
)
if not flt(item.transfer_qty):
frappe.throw(
_("Row {0}: Qty in Stock UOM can not be zero.").format(item.idx), title=_("Zero quantity")
)
def update_cost_in_project(self):
if self.work_order and not frappe.db.get_value(
@ -1382,7 +1386,6 @@ class StockEntry(StockController):
if self.purpose != "Send to Subcontractor" and self.purpose in ["Manufacture", "Repack"]:
scrap_item_dict = self.get_bom_scrap_material(self.fg_completed_qty)
for item in scrap_item_dict.values():
item.idx = ""
if self.pro_doc and self.pro_doc.scrap_warehouse:
item["to_warehouse"] = self.pro_doc.scrap_warehouse
@ -1898,7 +1901,6 @@ class StockEntry(StockController):
se_child.is_process_loss = item_row.get("is_process_loss", 0)
for field in [
"idx",
"po_detail",
"original_item",
"expense_account",

View File

@ -51,7 +51,6 @@ class TestStockEntry(FrappeTestCase):
def tearDown(self):
frappe.db.rollback()
frappe.set_user("Administrator")
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "0")
def test_fifo(self):
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
@ -767,13 +766,12 @@ class TestStockEntry(FrappeTestCase):
fg_cost, flt(rm_cost + bom_operation_cost + work_order.additional_operating_cost, 2)
)
@change_settings("Manufacturing Settings", {"material_consumption": 1})
def test_work_order_manufacture_with_material_consumption(self):
from erpnext.manufacturing.doctype.work_order.work_order import (
make_stock_entry as _make_stock_entry,
)
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "1")
bom_no = frappe.db.get_value("BOM", {"item": "_Test FG Item", "is_default": 1, "docstatus": 1})
work_order = frappe.new_doc("Work Order")
@ -983,43 +981,6 @@ class TestStockEntry(FrappeTestCase):
repack.insert()
self.assertRaises(frappe.ValidationError, repack.submit)
# def test_material_consumption(self):
# frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM")
# frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "0")
# from erpnext.manufacturing.doctype.work_order.work_order \
# import make_stock_entry as _make_stock_entry
# bom_no = frappe.db.get_value("BOM", {"item": "_Test FG Item 2",
# "is_default": 1, "docstatus": 1})
# work_order = frappe.new_doc("Work Order")
# work_order.update({
# "company": "_Test Company",
# "fg_warehouse": "_Test Warehouse 1 - _TC",
# "production_item": "_Test FG Item 2",
# "bom_no": bom_no,
# "qty": 4.0,
# "stock_uom": "_Test UOM",
# "wip_warehouse": "_Test Warehouse - _TC",
# "additional_operating_cost": 1000,
# "use_multi_level_bom": 1
# })
# work_order.insert()
# work_order.submit()
# make_stock_entry(item_code="_Test Serialized Item With Series", target="_Test Warehouse - _TC", qty=50, basic_rate=100)
# make_stock_entry(item_code="_Test Item 2", target="_Test Warehouse - _TC", qty=50, basic_rate=20)
# item_quantity = {
# '_Test Item': 2.0,
# '_Test Item 2': 12.0,
# '_Test Serialized Item With Series': 6.0
# }
# stock_entry = frappe.get_doc(_make_stock_entry(work_order.name, "Material Consumption for Manufacture", 2))
# for d in stock_entry.get('items'):
# self.assertEqual(item_quantity.get(d.item_code), d.qty)
def test_customer_provided_parts_se(self):
create_item(
"CUST-0987", is_customer_provided_item=1, customer="_Test Customer", is_purchase_item=0
@ -1358,6 +1319,13 @@ class TestStockEntry(FrappeTestCase):
issue.reload() # reload because reposting current voucher updates rate
self.assertEqual(issue.value_difference, -30)
def test_transfer_qty_validation(self):
se = make_stock_entry(item_code="_Test Item", do_not_save=True, qty=0.001, rate=100)
se.items[0].uom = "Kg"
se.items[0].conversion_factor = 0.002
self.assertRaises(frappe.ValidationError, se.save)
def make_serialized_item(**args):
args = frappe._dict(args)

View File

@ -526,7 +526,7 @@ def check_pending_reposting(posting_date: str, throw_error: bool = True) -> bool
filters = {
"docstatus": 1,
"status": ["in", ["Queued", "In Progress", "Failed"]],
"status": ["in", ["Queued", "In Progress"]],
"posting_date": ["<=", posting_date],
}