Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stock): Grab posting date/time from SABB #43493

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

cogk
Copy link
Contributor

@cogk cogk commented Oct 3, 2024

TypeError: combine() argument 1 must be datetime.date, not None

Hey 👋, sorry to bother you.

I see in the code below that a "fake" Stock Ledger Entry is constructed. However, there are two missing keys, namely "posting_date" and "posting_date". Because, they are expected a little bit after, saving the Stock Entry fails.

I just wanted an expert's opinion: is this a typo, a small oversight? Or should I dig down more.
Please note that I did not try to reproduce the issue yet, just doing things on instinct.

  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 1714, in get_valuation_rate
    batch_obj = BatchNoValuation(
			sle=frappe._dict(
				{
					"item_code": item_code,
					"warehouse": warehouse,
					"actual_qty": -1,
					"serial_and_batch_bundle": serial_and_batch_bundle,
#				-->	## Here there are missing keys: posting_date, posting_time
#				-->	## Let's just grab them from the SABB and call it a day
				}
			)
		)

Stack trace

  File "apps/frappe/frappe/desk/form/save.py", line 39, in savedocs
    doc.save()
      doc = <StockEntry: MAT-STE-2024-XXXXX>
  File "apps/frappe/frappe/model/document.py", line 1136, in run_before_save_methods
    self.run_method("validate")
  File "apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 238, in validate
    self.calculate_rate_and_amount()
  File "apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 777, in calculate_rate_and_amount
    self.set_basic_rate(reset_outgoing_rate, raise_error_if_no_rate)
  File "apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py", line 819, in set_basic_rate
    d.basic_rate = get_valuation_rate(
  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 1714, in get_valuation_rate
    batch_obj = BatchNoValuation(
			sle=frappe._dict(
				{
					"item_code": item_code,
					"warehouse": warehouse,
					"actual_qty": -1,
					"serial_and_batch_bundle": serial_and_batch_bundle,
					# HERE: Missing posting_date, posting_time
				}
			)
		)
  File "apps/erpnext/erpnext/stock/serial_batch_bundle.py", line 627, in __init__
    self.calculate_avg_rate()
  File "apps/erpnext/erpnext/stock/serial_batch_bundle.py", line 647, in calculate_avg_rate
    self.calculate_avg_rate_for_non_batchwise_valuation()
  File "apps/frappe/frappe/utils/deprecations.py", line 18, in wrapper
    return func(*args, **kwargs)
  File "apps/erpnext/erpnext/stock/deprecated_serial_batch.py", line 158, in calculate_avg_rate_for_non_batchwise_valuation
    self.set_balance_value_for_non_batchwise_valuation_batches()
  File "apps/frappe/frappe/utils/deprecations.py", line 18, in wrapper
    return func(*args, **kwargs)
  File "apps/erpnext/erpnext/stock/deprecated_serial_batch.py", line 190, in set_balance_value_for_non_batchwise_valuation_batches
    self.set_balance_value_from_sl_entries()
  File "apps/frappe/frappe/utils/deprecations.py", line 18, in wrapper
    return func(*args, **kwargs)
  File "apps/erpnext/erpnext/stock/deprecated_serial_batch.py", line 200, in set_balance_value_from_sl_entries
    posting_datetime = get_combine_datetime(self.sle.posting_date, self.sle.posting_time)
      self = <erpnext.stock.serial_batch_bundle.BatchNoValuation object>
  File "apps/erpnext/erpnext/stock/utils.py", line 669, in get_combine_datetime
    return datetime.datetime.combine(posting_date, posting_time).replace(microsecond=0)
      posting_date = None
      posting_time = None
TypeError: combine() argument 1 must be datetime.date, not None

@github-actions github-actions bot added needs-tests This PR needs automated unit-tests. stock labels Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-tests This PR needs automated unit-tests. stock
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant