-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6fe47f
commit 3a4d4ad
Showing
6 changed files
with
124 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
__version__ = "0.0.1" | ||
|
||
from erpnext.controllers.buying_controller import BuyingController | ||
from erpnext.controllers.stock_controller import StockController | ||
|
||
from asset.asset.controllers.buying_controller.buying_controller import AssetBuyingController | ||
from asset.asset.controllers.stock_controller.stock_controller import AssetStockController | ||
|
||
|
||
BuyingController.validate = AssetBuyingController.validate | ||
BuyingController.on_submit = AssetBuyingController.on_submit | ||
BuyingController.on_cancel = AssetBuyingController.on_cancel | ||
StockController.make_gl_entries = AssetStockController.make_gl_entries | ||
StockController.make_bundle_using_old_serial_batch_fields = AssetStockController.make_bundle_using_old_serial_batch_fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
asset/asset/controllers/stock_controller/override/bundle_using_old_serial_batch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import frappe | ||
|
||
def asset_make_bundle_using_old_serial_batch_fields(self, table_name=None, via_landed_cost_voucher=False): | ||
if self.get("_action") == "update_after_submit": | ||
return | ||
|
||
# To handle test cases | ||
if frappe.flags.in_test and frappe.flags.use_serial_and_batch_fields: | ||
return | ||
|
||
if not table_name: | ||
table_name = "items" | ||
|
||
if self.doctype == "Asset Capitalization": | ||
table_name = "stock_items" | ||
|
||
for row in self.get(table_name): | ||
if row.serial_and_batch_bundle and (row.serial_no or row.batch_no): | ||
self.validate_serial_nos_and_batches_with_bundle(row) | ||
|
||
if not row.serial_no and not row.batch_no and not row.get("rejected_serial_no"): | ||
continue | ||
|
||
if not row.use_serial_batch_fields and ( | ||
row.serial_no or row.batch_no or row.get("rejected_serial_no") | ||
): | ||
row.use_serial_batch_fields = 1 | ||
|
||
if row.use_serial_batch_fields and ( | ||
not row.serial_and_batch_bundle and not row.get("rejected_serial_and_batch_bundle") | ||
): | ||
bundle_details = { | ||
"item_code": row.get("rm_item_code") or row.item_code, | ||
"posting_date": self.posting_date, | ||
"posting_time": self.posting_time, | ||
"voucher_type": self.doctype, | ||
"voucher_no": self.name, | ||
"voucher_detail_no": row.name, | ||
"company": self.company, | ||
"is_rejected": 1 if row.get("rejected_warehouse") else 0, | ||
"use_serial_batch_fields": row.use_serial_batch_fields, | ||
"via_landed_cost_voucher": via_landed_cost_voucher, | ||
"do_not_submit": True if not via_landed_cost_voucher else False, | ||
} | ||
|
||
if row.get("qty") or row.get("consumed_qty") or row.get("stock_qty"): | ||
self.update_bundle_details(bundle_details, table_name, row) | ||
self.create_serial_batch_bundle(bundle_details, row) | ||
|
||
if row.get("rejected_qty"): | ||
self.update_bundle_details(bundle_details, table_name, row, is_rejected=True) | ||
self.create_serial_batch_bundle(bundle_details, row) |
38 changes: 38 additions & 0 deletions
38
asset/asset/controllers/stock_controller/override/make_gl_entries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import frappe | ||
from frappe.utils import cint | ||
|
||
import erpnext | ||
from erpnext.accounts.general_ledger import ( | ||
make_gl_entries, | ||
make_reverse_gl_entries, | ||
) | ||
from erpnext.stock import get_warehouse_account_map | ||
|
||
|
||
def asset_make_gl_entries(self, gl_entries=None, from_repost=False, via_landed_cost_voucher=False): | ||
if self.docstatus == 2: | ||
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name) | ||
|
||
provisional_accounting_for_non_stock_items = cint( | ||
frappe.get_cached_value( | ||
"Company", self.company, "enable_provisional_accounting_for_non_stock_items" | ||
) | ||
) | ||
|
||
is_asset_pr = any(d.get("is_fixed_asset") for d in self.get("items")) | ||
|
||
if ( | ||
cint(erpnext.is_perpetual_inventory_enabled(self.company)) | ||
or provisional_accounting_for_non_stock_items | ||
or is_asset_pr | ||
): | ||
warehouse_account = get_warehouse_account_map(self.company) | ||
|
||
if self.docstatus == 1: | ||
if not gl_entries: | ||
gl_entries = ( | ||
self.get_gl_entries(warehouse_account, via_landed_cost_voucher) | ||
if self.doctype == "Purchase Receipt" | ||
else self.get_gl_entries(warehouse_account) | ||
) | ||
make_gl_entries(gl_entries, from_repost=from_repost) |
13 changes: 13 additions & 0 deletions
13
asset/asset/controllers/stock_controller/stock_controller.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from erpnext.controllers.stock_controller import StockController | ||
|
||
from asset.asset.controllers.stock_controller.override.make_gl_entries import asset_make_gl_entries | ||
from asset.asset.controllers.stock_controller.override.bundle_using_old_serial_batch import asset_make_bundle_using_old_serial_batch_fields | ||
|
||
class AssetStockController(StockController): | ||
def make_gl_entries(self, gl_entries=None, from_repost=False, via_landed_cost_voucher=False): | ||
asset_make_gl_entries(self, gl_entries=None, from_repost=False, via_landed_cost_voucher=False) | ||
|
||
|
||
def make_bundle_using_old_serial_batch_fields(self, table_name=None, via_landed_cost_voucher=False): | ||
asset_make_bundle_using_old_serial_batch_fields(self, table_name=None, via_landed_cost_voucher=False) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters