Skip to content

Commit

Permalink
debug: CI Server Test
Browse files Browse the repository at this point in the history
  • Loading branch information
marination committed Jun 8, 2022
1 parent ff0a6b7 commit 6dd3263
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/server-tests-mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
FRAPPE_BRANCH: ${{ github.event.inputs.branch }}

- name: Run Tests
run: cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --app erpnext --use-orchestrator --with-coverage
run: cd ~/frappe-bench/ && bench --site test_site run-tests --app erpnext --doctype "BOM"
env:
TYPE: server
CI_BUILD_ID: ${{ github.run_id }}
Expand Down
11 changes: 8 additions & 3 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ def get_rm_rate(self, arg):
rate = flt(self.get_bom_unitcost(arg["bom_no"])) * (arg.get("conversion_factor") or 1)
else:
rate = get_bom_item_rate(arg, self)

if not rate:
if self.rm_cost_as_per == "Price List":
frappe.msgprint(
Expand All @@ -378,7 +377,14 @@ def get_rm_rate(self, arg):
frappe.msgprint(
_("{0} not found for item {1}").format(self.rm_cost_as_per, arg["item_code"]), alert=True
)
return flt(rate) * flt(self.plc_conversion_rate or 1) / (self.conversion_rate or 1)

# Consider plc_conversion_rate value only if cost is fetched as per Price List
if self.rm_cost_as_per == "Price List":
plc_conversion_rate = self.plc_conversion_rate or 1
else:
plc_conversion_rate = 1

return flt(rate) * flt(plc_conversion_rate) / (self.conversion_rate or 1)

@frappe.whitelist()
def update_cost(self, update_parent=True, from_child_bom=False, update_hour_rate=True, save=True):
Expand Down Expand Up @@ -652,7 +658,6 @@ def calculate_rm_cost(self, save=False):
"sourced_by_supplier": d.sourced_by_supplier,
}
)

d.base_rate = flt(d.rate) * flt(self.conversion_rate)
d.amount = flt(d.rate, d.precision("rate")) * flt(d.qty, d.precision("qty"))
d.base_amount = d.amount * flt(self.conversion_rate)
Expand Down
25 changes: 16 additions & 9 deletions erpnext/manufacturing/doctype/bom/test_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,33 @@ def _get_default_bom_in_item():

def test_update_bom_cost_in_all_boms(self):
# get current rate for '_Test Item 2'
rm_rate = frappe.db.sql(
"""select rate from `tabBOM Item`
where parent='BOM-_Test Item Home Desktop Manufactured-001'
and item_code='_Test Item 2' and docstatus=1 and parenttype='BOM'"""
bom_rates = frappe.db.get_values(
"BOM Item",
{
"parent": "BOM-_Test Item Home Desktop Manufactured-001",
"item_code": "_Test Item 2",
"docstatus": 1,
},
fieldname=["rate", "base_rate"],
as_dict=True,
)
rm_rate = rm_rate[0][0] if rm_rate else 0
rm_base_rate = bom_rates[0].get("base_rate") if bom_rates else 0
rm_rate = bom_rates[0].get("rate") if bom_rates else 0
print("rm_rate", rm_base_rate, rm_rate)

# Reset item valuation rate
reset_item_valuation_rate(item_code="_Test Item 2", qty=200, rate=rm_rate + 10)

reset_item_valuation_rate(item_code="_Test Item 2", qty=200, rate=rm_base_rate + 10)
print(frappe.db.get_all("Bin", {"item_code": "_Test Item 2"}, ["*"]))
# update cost of all BOMs based on latest valuation rate
update_cost_in_all_boms_in_test()

# check if new valuation rate updated in all BOMs
for d in frappe.db.sql(
"""select rate from `tabBOM Item`
"""select base_rate from `tabBOM Item`
where item_code='_Test Item 2' and docstatus=1 and parenttype='BOM'""",
as_dict=1,
):
self.assertEqual(d.rate, rm_rate + 10)
self.assertEqual(d.base_rate, rm_base_rate + 10)

def test_bom_cost(self):
bom = frappe.copy_doc(test_records[2])
Expand Down

0 comments on commit 6dd3263

Please sign in to comment.