removed duplicate function and other CLI fixes (#12876)
* merge shelf like and manufacturing date * setting default manufacturing date as todays date * setting default manufacturing date as todays date * fix * Improvements to batch auto naming (#12496) * refactor: add new function - batch_uses_naming_series use batch_uses_naming_series in autoname method * properly update naming series on delete: - add new functions - get_batch_prefix, get_batch_naming_series_key, get_batch_naming_series - refactor get_name_from_naming_series - add after_delete method * add documentation and rename some functions * PEP 8 compliance * test * added support for jinja template and added validation if expiry date is set or not if item has_expiry_date is set * bug fix, renamed item_code to item as in batch doctype we refer 'item code' by 'item' * added manufacturing date wise sort * added prefix to expiry date and manufacturing date * Quality Review fixes
This commit is contained in:
parent
a8d10b7332
commit
a4ff220769
@ -7,9 +7,8 @@ from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.naming import make_autoname, revert_series_if_last
|
||||
from frappe.utils import flt, cint
|
||||
from frappe.utils.jinja import render_template, validate_template
|
||||
from frappe.utils.jinja import render_template
|
||||
from frappe.utils.data import add_days
|
||||
import json
|
||||
|
||||
class UnableToSelectBatchError(frappe.ValidationError):
|
||||
pass
|
||||
@ -83,60 +82,6 @@ def get_batch_naming_series():
|
||||
return series
|
||||
|
||||
|
||||
def batch_uses_naming_series():
|
||||
"""
|
||||
Verify if the Batch is to be named using a naming series
|
||||
:return: bool
|
||||
"""
|
||||
use_naming_series = cint(frappe.db.get_single_value('Stock Settings', 'use_naming_series'))
|
||||
return bool(use_naming_series)
|
||||
|
||||
|
||||
def _get_batch_prefix():
|
||||
"""
|
||||
Get the naming series prefix set in Stock Settings.
|
||||
|
||||
It does not do any sanity checks so make sure to use it after checking if the Batch
|
||||
is set to use naming series.
|
||||
:return: The naming series.
|
||||
"""
|
||||
naming_series_prefix = frappe.db.get_single_value('Stock Settings', 'naming_series_prefix')
|
||||
if not naming_series_prefix:
|
||||
naming_series_prefix = 'BATCH-'
|
||||
|
||||
return naming_series_prefix
|
||||
|
||||
|
||||
def _make_naming_series_key(prefix):
|
||||
"""
|
||||
Make naming series key for a Batch.
|
||||
|
||||
Naming series key is in the format [prefix].[#####]
|
||||
:param prefix: Naming series prefix gotten from Stock Settings
|
||||
:return: The derived key. If no prefix is given, an empty string is returned
|
||||
"""
|
||||
if not unicode(prefix):
|
||||
return ''
|
||||
else:
|
||||
return prefix.upper() + '.#####'
|
||||
|
||||
|
||||
def get_batch_naming_series():
|
||||
"""
|
||||
Get naming series key for a Batch.
|
||||
|
||||
Naming series key is in the format [prefix].[#####]
|
||||
:return: The naming series or empty string if not available
|
||||
"""
|
||||
series = ''
|
||||
if batch_uses_naming_series():
|
||||
prefix = _get_batch_prefix()
|
||||
key = _make_naming_series_key(prefix)
|
||||
series = key
|
||||
|
||||
return series
|
||||
|
||||
|
||||
class Batch(Document):
|
||||
def autoname(self):
|
||||
"""Generate random ID for batch if not specified"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user