Skip to content

Commit

Permalink
ci: track overrides for stock and manufacturing cycles (v15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohan Bansal committed May 30, 2024
1 parent ffb173d commit 578a407
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 146 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Track Overrides

on:
pull_request:
branches:
- version-14
- version-15

jobs:
track_overrides:
runs-on: ubuntu-latest
name: Track Overrides
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Track Overrides
uses: diamorafaela/track-overrides@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
35 changes: 20 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
exclude: 'node_modules|.git'
exclude: "node_modules|.git"
default_stages: [commit]
fail_fast: false

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
files: 'beam.*'
exclude: '.*json$|.*txt$|.*csv|.*md|.*svg'
files: "inventory_tools.*"
exclude: ".*json$|.*txt$|.*csv|.*md|.*svg"
- id: check-yaml
- id: no-commit-to-branch
args: ['--branch', 'develop']
args: ["--branch", "version-15"]
- id: check-merge-conflict
- id: check-ast
- id: check-json
Expand All @@ -23,7 +23,7 @@ repos:
rev: v2.34.0
hooks:
- id: pyupgrade
args: ['--py38-plus']
args: ["--py310-plus"]

- repo: https://github.com/frappe/black
rev: 951ccf4d5bb0d692b457a5ebc4215d755618eb68
Expand All @@ -38,12 +38,10 @@ repos:
# Ignore any files that might contain jinja / bundles
exclude: |
(?x)^(
beam/public/dist/.*|
.*node_modules.*|
.*boilerplate.*|
beam/www/website_script.js|
beam/templates/includes/.*|
beam/public/js/lib/.*
inventory_tools/public/dist/.*|
inventory_tools/public/js/lib/.*|
inventory_tools/templates/includes/.*
)$
- repo: https://github.com/PyCQA/isort
Expand All @@ -55,7 +53,7 @@ repos:
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: ['flake8-bugbear']
additional_dependencies: ["flake8-bugbear"]

- repo: local
hooks:
Expand All @@ -66,7 +64,14 @@ repos:
language: system
types: [python]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
exclude: ^tests/
args: [--ignore-missing-imports]

ci:
autoupdate_schedule: weekly
skip: []
submodules: false
autoupdate_schedule: weekly
skip: []
submodules: false
16 changes: 8 additions & 8 deletions inventory_tools/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

# include js in doctype views
doctype_js = {
"Work Order": "public/js/work_order_custom.js",
"Purchase Order": "public/js/purchase_order_custom.js",
"Purchase Invoice": "public/js/purchase_invoice_custom.js",
"Stock Entry": "public/js/stock_entry_custom.js",
"Job Card": "public/js/job_card_custom.js",
"Operation": "public/js/operation_custom.js",
"Purchase Invoice": "public/js/purchase_invoice_custom.js",
"Purchase Order": "public/js/purchase_order_custom.js",
"Stock Entry": "public/js/stock_entry_custom.js",
"Work Order": "public/js/work_order_custom.js",
}
# doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
# doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"}
Expand Down Expand Up @@ -109,14 +109,14 @@
# Override standard doctype classes

override_doctype_class = {
"Work Order": "inventory_tools.inventory_tools.overrides.work_order.InventoryToolsWorkOrder",
"Job Card": "inventory_tools.inventory_tools.overrides.job_card.InventoryToolsJobCard",
"Production Plan": "inventory_tools.inventory_tools.overrides.production_plan.InventoryToolsProductionPlan",
"Purchase Invoice": "inventory_tools.inventory_tools.overrides.purchase_invoice.InventoryToolsPurchaseInvoice",
"Purchase Order": "inventory_tools.inventory_tools.overrides.purchase_order.InventoryToolsPurchaseOrder",
"Purchase Receipt": "inventory_tools.inventory_tools.overrides.purchase_receipt.InventoryToolsPurchaseReceipt",
"Production Plan": "inventory_tools.inventory_tools.overrides.production_plan.InventoryToolsProductionPlan",
"Stock Entry": "inventory_tools.inventory_tools.overrides.stock_entry.InventoryToolsStockEntry",
"Job Card": "inventory_tools.inventory_tools.overrides.job_card.InventoryToolsJobCard",
"Sales Order": "inventory_tools.inventory_tools.overrides.sales_order.InventoryToolsSalesOrder",
"Stock Entry": "inventory_tools.inventory_tools.overrides.stock_entry.InventoryToolsStockEntry",
"Work Order": "inventory_tools.inventory_tools.overrides.work_order.InventoryToolsWorkOrder",
}


Expand Down
7 changes: 7 additions & 0 deletions inventory_tools/inventory_tools/overrides/job_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class InventoryToolsJobCard(JobCard):
def validate_job_card(self):
"""
HASH: 6554f192fbe90033a71fa323462633c5130e1b46
REPO: https://github.com/frappe/erpnext/
PATH: erpnext/manufacturing/doctype/job_card/job_card.py
METHOD: validate_job_card
"""

if (
self.work_order
and frappe.get_cached_value("Work Order", self.work_order, "status") == "Stopped"
Expand Down
102 changes: 59 additions & 43 deletions inventory_tools/inventory_tools/overrides/production_plan.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,59 @@
import json

import frappe
from erpnext.manufacturing.doctype.production_plan.production_plan import ProductionPlan
from erpnext.manufacturing.doctype.work_order.work_order import get_default_warehouse


class InventoryToolsProductionPlan(ProductionPlan):
@frappe.whitelist()
def make_work_order(self):
wo_list, po_list = [], []
subcontracted_po = {}
default_warehouses = get_default_warehouse()

self.make_work_order_for_finished_goods(wo_list, default_warehouses)
self.make_work_order_for_subassembly_items(wo_list, subcontracted_po, default_warehouses)
if frappe.get_value("Inventory Tools Settings", self.company, "create_purchase_orders"):
self.make_subcontracted_purchase_order(subcontracted_po, po_list)
self.show_list_created_message("Work Order", wo_list)
self.show_list_created_message("Purchase Order", po_list)

def make_work_order_for_subassembly_items(self, wo_list, subcontracted_po, default_warehouses):
for row in self.sub_assembly_items:
if row.type_of_manufacturing == "Subcontract":
subcontracted_po.setdefault(row.supplier, []).append(row)
if not frappe.get_value(
"Inventory Tools Settings", self.company, "enable_work_order_subcontracting"
):
continue

if row.type_of_manufacturing == "Material Request":
continue

work_order_data = {
"wip_warehouse": default_warehouses.get("wip_warehouse"),
"fg_warehouse": default_warehouses.get("fg_warehouse"),
"company": self.get("company"),
}

self.prepare_data_for_sub_assembly_items(row, work_order_data)
work_order = self.create_work_order(work_order_data)
if work_order:
wo_list.append(work_order)
import frappe
from erpnext.manufacturing.doctype.production_plan.production_plan import ProductionPlan
from erpnext.manufacturing.doctype.work_order.work_order import get_default_warehouse
from frappe import _


class InventoryToolsProductionPlan(ProductionPlan):
@frappe.whitelist()
def make_work_order(self):
"""
HASH: 544e56a71cac8751f5ff9fb7c32fe3a0e9f3eb85
REPO: https://github.com/frappe/erpnext/
PATH: erpnext/manufacturing/doctype/production_plan/production_plan.py
METHOD: make_work_order
"""

wo_list, po_list = [], []
subcontracted_po = {}
default_warehouses = get_default_warehouse()

self.make_work_order_for_finished_goods(wo_list, default_warehouses)
self.make_work_order_for_subassembly_items(wo_list, subcontracted_po, default_warehouses)
if frappe.get_value("Inventory Tools Settings", self.company, "create_purchase_orders"):
self.make_subcontracted_purchase_order(subcontracted_po, po_list)
self.show_list_created_message("Work Order", wo_list)
self.show_list_created_message("Purchase Order", po_list)

if not wo_list:
frappe.msgprint(_("No Work Orders were created"))

def make_work_order_for_subassembly_items(self, wo_list, subcontracted_po, default_warehouses):
"""
HASH: 544e56a71cac8751f5ff9fb7c32fe3a0e9f3eb85
REPO: https://github.com/frappe/erpnext/
PATH: erpnext/manufacturing/doctype/production_plan/production_plan.py
METHOD: make_work_order_for_subassembly_items
"""

for row in self.sub_assembly_items:
if row.type_of_manufacturing == "Subcontract":
subcontracted_po.setdefault(row.supplier, []).append(row)
if not frappe.get_value(
"Inventory Tools Settings", self.company, "enable_work_order_subcontracting"
):
continue

if row.type_of_manufacturing == "Material Request":
continue

work_order_data = {
"wip_warehouse": default_warehouses.get("wip_warehouse"),
"fg_warehouse": default_warehouses.get("fg_warehouse"),
"company": self.get("company"),
}

self.prepare_data_for_sub_assembly_items(row, work_order_data)
work_order = self.create_work_order(work_order_data)
if work_order:
wo_list.append(work_order)
18 changes: 18 additions & 0 deletions inventory_tools/inventory_tools/overrides/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
class InventoryToolsStockEntry(StockEntry):
def check_if_operations_completed(self):
"""
HASH: dc0bb220ed2d7a7e0bb2db8d284480d051b9e221
REPO: https://github.com/frappe/erpnext/
PATH: erpnext/stock/doctype/stock_entry/stock_entry.py
METHOD: check_if_operations_completed
Original code checks that the stock entry amount plus what's already produced in the WO
is not larger than any operation's completed quantity (plus the overallowance amount).
Since customized code rewires so stock entries happen via a Job Card, the function now
checks that the stock entry amount plus what's already been produced in the WO is not
greater than the amount to be manufactured plus the overallowance amount.
"""

prod_order = frappe.get_doc("Work Order", self.work_order)
allowance_percentage = get_allowance_percentage(self.company, self.bom_no)

Expand Down Expand Up @@ -45,10 +51,16 @@ def check_if_operations_completed(self):

def validate_finished_goods(self):
"""
HASH: dc0bb220ed2d7a7e0bb2db8d284480d051b9e221
REPO: https://github.com/frappe/erpnext/
PATH: erpnext/stock/doctype/stock_entry/stock_entry.py
METHOD: validate_finished_goods
1. Check if FG exists (mfg, repack)
2. Check if Multiple FG Items are present (mfg)
3. Check FG Item and Qty against WO if present (mfg)
"""

production_item, wo_qty, finished_items = None, 0, []

wo_details = frappe.db.get_value("Work Order", self.work_order, ["production_item", "qty"])
Expand Down Expand Up @@ -105,9 +117,15 @@ def validate_finished_goods(self):

def get_pending_raw_materials(self, backflush_based_on=None):
"""
HASH: dc0bb220ed2d7a7e0bb2db8d284480d051b9e221
REPO: https://github.com/frappe/erpnext/
PATH: erpnext/stock/doctype/stock_entry/stock_entry.py
METHOD: get_pending_raw_materials
issue (item quantity) that is pending to issue or desire to transfer,
whichever is less
"""

item_dict = self.get_pro_order_required_items(backflush_based_on)

max_qty = flt(self.pro_doc.qty)
Expand Down
Loading

0 comments on commit 578a407

Please sign in to comment.