Esempio n. 1
0
 def make_sl_entries(self,
                     sl_entries,
                     allow_negative_stock=False,
                     via_landed_cost_voucher=False):
     from erpnext.stock.stock_ledger import make_sl_entries
     make_sl_entries(sl_entries, allow_negative_stock,
                     via_landed_cost_voucher)
Esempio n. 2
0
	def process_material_according_to_indent(self):

		sl_entries = []

		stock_transfer_map = self.compute_items_to_be_moved_for_refill_and_return()

		self.transfer_stock_to_ba(sl_entries, stock_transfer_map)

		self.transfer_stock_to_bottling_plant(sl_entries, stock_transfer_map)

		stock_transfer_map = self.compute_items_to_be_moved_back_after_refill_and_oneway()

		self.transfer_stock_back_to_ba(sl_entries, stock_transfer_map)

		self.transfer_stock_back_to_logistics_partner(sl_entries, stock_transfer_map)

		make_sl_entries(sl_entries)
def repost_stock_entry(doc):
    doc.db_update()
    for child_row in doc.items:
        if child_row.is_finished_item:
            child_row.db_update()

    sl_entries = []
    finished_item_row = doc.get_finished_item_row()
    get_sle_for_target_warehouse(doc, sl_entries, finished_item_row)

    if sl_entries:
        try:
            make_sl_entries(sl_entries, True)
        except Exception:
            print(f'SLE entries not posted for the stock entry {doc.name}')
            traceback = frappe.get_traceback()
            frappe.log_error(traceback)
Esempio n. 4
0
    def transfer_stock(self):

        self.set_missing_values()

        from flows import utils as flow_utils

        stock_owner = flow_utils.get_stock_owner_via_sales_person_tree(
            self.driver)
        stock_owner = stock_owner if stock_owner else self.vehicle

        stock_owner_act = utils.get_or_create_vehicle_stock_account(
            stock_owner, self.company)
        stock_owner_act_name = stock_owner_act.name

        sl_entries = []

        for d in self.items:
            sl_entries.append(
                self.get_sl_entry({
                    "item_code":
                    d.item,
                    "actual_qty":
                    -1 * d.quantity,
                    "warehouse":
                    self.warehouse if self.gatepass_type.lower() == 'out' else
                    stock_owner_act_name
                }))

            sl_entries.append(
                self.get_sl_entry({
                    "item_code":
                    d.item,
                    "actual_qty":
                    1 * d.quantity,
                    "warehouse":
                    self.warehouse if self.gatepass_type.lower() == 'in' else
                    stock_owner_act_name
                }))

        from erpnext.stock.stock_ledger import make_sl_entries

        make_sl_entries(sl_entries)
Esempio n. 5
0
    def transfer_stock(self, is_cancelled=None):

        if utils.cint(self.cancelled) == 1:
            return

        if not self.stock_date or self.stock_date.strip() == '':
            return

        is_cancelled = is_cancelled if is_cancelled is not None else (
            self.docstatus == 2 and "Yes" or "No")

        stock_owner = utils.get_stock_owner_via_sales_person_tree(
            self.stock_owner)
        stock_owner_warehouse = utils.get_or_create_warehouse(
            stock_owner, self.stock_owner_company)

        sl_entries = []

        if self.transaction_type in ("Refill", "New Connection"):
            sl_entries.append(
                self.get_sl_entry({
                    "item_code": self.item,
                    "actual_qty": -1 * self.qty,
                    "warehouse": stock_owner_warehouse.name,
                    "process": self.transaction_type,
                    "is_cancelled": is_cancelled,
                    "posting_date": self.stock_date,
                }))

        # if refill sale or tv-out
        if self.transaction_type in ('Refill', 'TV Out'):
            sl_entries.append(
                self.get_sl_entry({
                    "item_code": self.item.replace('F', 'E'),
                    "actual_qty": self.qty,
                    "warehouse": stock_owner_warehouse.name,
                    "process": self.transaction_type,
                    "is_cancelled": is_cancelled,
                    "posting_date": self.stock_date,
                }))

        make_sl_entries(sl_entries)
Esempio n. 6
0
	def make_stock_refill_entry(self):
		if cint(self.sub_contracted) == 1:
			return

		supplier_warehouse_account = frappe.get_doc("Warehouse", self.warehouse)

		stock_refill_entries = self.convert_stock_in_place(
			supplier_warehouse_account,
			self.item.replace('F', 'E'),
			self.qty,
			self.item,
			self.qty,
			process='Refill'
		)

		root.debug({
		"stock_refill_entries": stock_refill_entries,
		"supplier_warehouse_account": supplier_warehouse_account.name,
		})

		make_sl_entries(stock_refill_entries)
Esempio n. 7
0
    def transfer_stock(self):

        if cint(self.cancelled) == 1:
            return

        from erpnext.stock.stock_ledger import make_sl_entries

        self.set_missing_values()

        # Commented for staggered phase 1
        # transportation_vehicle_warehouse = utils.get_or_create_vehicle_stock_account(self.vehicle, self.company)
        # transportation_vehicle_warehouse_name = transportation_vehicle_warehouse.name

        transportation_vehicle_warehouse_name = self.warehouse

        # TODO: write a method to find the same
        customer_warehouse_name = utils.get_or_create_customer_stock_account(
            self.customer, self.company).name

        sl_entries = []

        if self.item_delivered and self.delivered_quantity:
            sl_entries.append(
                self.get_sl_entry({
                    "item_code":
                    self.item_delivered,
                    "actual_qty":
                    -1 * self.delivered_quantity,
                    "warehouse":
                    transportation_vehicle_warehouse_name
                }))

            sl_entries.append(
                self.get_sl_entry({
                    "item_code": self.item_delivered,
                    "actual_qty": self.delivered_quantity,
                    "warehouse": customer_warehouse_name
                }))

        if self.item_received and self.received_quantity:

            if self.item_received.startswith('E'):

                empty_cylinders_available_at_customers_warehouse = frappe.db.sql(
                    """
                SELECT sum(actual_qty) AS current_quantity FROM `tabStock Ledger Entry` WHERE docstatus < 2
                AND item_code="{}" AND warehouse="{}";
                """.format(self.item_received, customer_warehouse_name),
                    as_dict=1)[0]['current_quantity']

                empty_cylinders_available_at_customers_warehouse = empty_cylinders_available_at_customers_warehouse \
                 if empty_cylinders_available_at_customers_warehouse else 0

                filled_cylinders_available_at_customers_warehouse = frappe.db.sql(
                    """
                SELECT sum(actual_qty) AS current_quantity FROM `tabStock Ledger Entry` WHERE docstatus < 2
                AND item_code="{}" AND warehouse="{}";
                """.format(self.item_received.replace('E', 'F'),
                           customer_warehouse_name),
                    as_dict=1)[0]['current_quantity']

                filled_cylinders_available_at_customers_warehouse = filled_cylinders_available_at_customers_warehouse \
                 if filled_cylinders_available_at_customers_warehouse else 0

                new_empty_cylinder_quantity = empty_cylinders_available_at_customers_warehouse - self.received_quantity

                if new_empty_cylinder_quantity < 0:
                    cylinders_consumed_from_last_gr_entry = min(
                        -1 * new_empty_cylinder_quantity,
                        filled_cylinders_available_at_customers_warehouse)
                else:
                    cylinders_consumed_from_last_gr_entry = 0

                if cylinders_consumed_from_last_gr_entry > 0:

                    for sl_e in self.convert_items_empty_in_place(
                            self.item_received.replace('E', 'F'),
                            self.item_received,
                            cylinders_consumed_from_last_gr_entry,
                            customer_warehouse_name):
                        sl_e['process'] = 'Consumption'
                        sl_entries.append(sl_e)

            sl_entries.append(
                self.get_sl_entry({
                    "item_code": self.item_received,
                    "actual_qty": -1 * self.received_quantity,
                    "warehouse": customer_warehouse_name
                }))

            sl_entries.append(
                self.get_sl_entry({
                    "item_code":
                    self.item_received,
                    "actual_qty":
                    1 * self.received_quantity,
                    "warehouse":
                    transportation_vehicle_warehouse_name
                }))

        make_sl_entries(sl_entries)
Esempio n. 8
0
	def make_sl_entries(self, sl_entries, is_amended=None):
		from erpnext.stock.stock_ledger import make_sl_entries
		make_sl_entries(sl_entries, is_amended)
Esempio n. 9
0
	def make_sl_entries(self, sl_entries, is_amended=None, allow_negative_stock=False,
			via_landed_cost_voucher=False):
		from erpnext.stock.stock_ledger import make_sl_entries
		make_sl_entries(sl_entries, is_amended, allow_negative_stock, via_landed_cost_voucher)
Esempio n. 10
0
 def make_sl_entries(self,
                     sl_entries,
                     is_amended=None,
                     allow_negative_stock=False):
     from erpnext.stock.stock_ledger import make_sl_entries
     make_sl_entries(sl_entries, is_amended, allow_negative_stock)
Esempio n. 11
0
 def make_sl_entries(self, sl_entries, is_amended=None):
     from erpnext.stock.stock_ledger import make_sl_entries
     make_sl_entries(sl_entries, is_amended)
Esempio n. 12
0
def update_stock_ledger(self):
    #frappe.msgprint('update_stock_ledger')
    from erpnext.controllers.selling_controller import SellingController
    from erpnext.controllers.stock_controller import StockController
    from erpnext.stock.get_item_details import get_conversion_factor
    from erpnext.stock.stock_ledger import make_sl_entries

    SellingController.update_reserved_qty(self)

    sl_entries = []
    for d in self.get_item_list():
        if frappe.get_cached_value("Item", d.item_code,
                                   "is_stock_item") == 1 and flt(d.qty):
            if flt(d.conversion_factor) == 0.0:
                d.conversion_factor = get_conversion_factor(
                    d.item_code, d.uom).get("conversion_factor") or 1.0
            return_rate = 0
            if cint(self.is_return
                    ) and self.return_against and self.docstatus == 1:
                return_rate = self.get_incoming_rate_for_sales_return(
                    d.item_code, self.return_against)

            # On cancellation or if return entry submission, make stock ledger entry for
            # target warehouse first, to update serial no values properly

            if d.warehouse and (
                (not cint(self.is_return) and self.docstatus == 1) or
                (cint(self.is_return) and self.docstatus == 2)):
                sl_entries.append(
                    self.get_sl_entries(
                        d, {
                            "actual_qty": -1 * flt(d.qty),
                            "incoming_rate": return_rate
                        }))

            if d.target_warehouse:
                target_warehouse_sle = self.get_sl_entries(
                    d, {
                        "actual_qty": flt(d.qty),
                        "warehouse": d.target_warehouse
                    })

                if self.docstatus == 1:
                    if not cint(self.is_return):
                        args = frappe._dict({
                            "item_code": d.item_code,
                            "warehouse": d.warehouse,
                            "posting_date": self.posting_date,
                            "posting_time": self.posting_time,
                            "qty": -1 * flt(d.qty),
                            "serial_no": d.serial_no,
                            "company": d.company,
                            "voucher_type": d.voucher_type,
                            "voucher_no": d.name,
                            "allow_zero_valuation": d.allow_zero_valuation,
                            "batch_no": d.batch_no  # FinByz Changes
                        })
                        target_warehouse_sle.update(
                            {"incoming_rate": get_incoming_rate(args)})
                    else:
                        target_warehouse_sle.update(
                            {"outgoing_rate": return_rate})
                sl_entries.append(target_warehouse_sle)

            if d.warehouse and (
                (not cint(self.is_return) and self.docstatus == 2) or
                (cint(self.is_return) and self.docstatus == 1)):
                sl_entries.append(
                    self.get_sl_entries(
                        d, {
                            "actual_qty": -1 * flt(d.qty),
                            "incoming_rate": return_rate
                        }))
    make_sl_entries(sl_entries)
	def make_sl_entries(self, sl_entries, is_amended=None, allow_negative_stock=False):
		from erpnext.stock.stock_ledger import make_sl_entries
		make_sl_entries(sl_entries, is_amended, allow_negative_stock)