Skip to content

Commit

Permalink
Merge pull request #5 from alyf-de/virtual-item-details
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra authored Oct 14, 2024
2 parents 799d24b + 626734a commit 1fbc582
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"company",
"customer",
"customer_name",
"currency",
"column_break_3",
"start_date",
"period_type",
Expand All @@ -27,7 +28,8 @@
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Customer",
"options": "Customer"
"options": "Customer",
"reqd": 1
},
{
"fieldname": "items",
Expand Down Expand Up @@ -90,13 +92,15 @@
"description": "Invoices will be generated for periods starting on or after this date.",
"fieldname": "start_date",
"fieldtype": "Date",
"label": "Start Date"
"label": "Start Date",
"reqd": 1
},
{
"fieldname": "company",
"fieldtype": "Link",
"label": "Company",
"options": "Company"
"options": "Company",
"reqd": 1
},
{
"default": "after end of period",
Expand All @@ -111,6 +115,15 @@
"fieldtype": "Select",
"label": "Billing Period is based on",
"options": "calendar months\nstart date"
},
{
"fetch_from": "company.default_currency",
"fetch_if_empty": 1,
"fieldname": "currency",
"fieldtype": "Link",
"label": "Currency",
"options": "Currency",
"reqd": 1
}
],
"is_submittable": 1,
Expand All @@ -120,7 +133,7 @@
"link_fieldname": "simple_subscription"
}
],
"modified": "2024-08-20 20:19:15.055024",
"modified": "2024-09-12 12:54:00.717315",
"modified_by": "Administrator",
"module": "Simple Subscription",
"name": "Simple Subscription",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,64 @@
"engine": "InnoDB",
"field_order": [
"item",
"qty"
"item_name",
"qty",
"current_rate",
"current_description"
],
"fields": [
{
"fieldname": "item",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Item",
"options": "Item"
},
{
"columns": 2,
"fieldname": "qty",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Qty"
},
{
"columns": 2,
"fieldname": "current_rate",
"fieldtype": "Currency",
"in_list_view": 1,
"in_standard_filter": 1,
"is_virtual": 1,
"label": "Current Rate",
"options": "currency"
},
{
"fieldname": "current_description",
"fieldtype": "Text Editor",
"is_virtual": 1,
"label": "Current Description",
"read_only": 1
},
{
"columns": 4,
"fieldname": "item_name",
"fieldtype": "Data",
"is_virtual": 1,
"label": "Item Name",
"read_only": 1
},
{
"columns": 2,
"fieldname": "item",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Item",
"options": "Item",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-02-04 16:18:56.506335",
"modified": "2024-09-12 18:37:52.687442",
"modified_by": "Administrator",
"module": "Simple Subscription",
"name": "Simple Subscription Item",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC"
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
# Copyright (c) 2022, ALYF GmbH and contributors
# For license information, please see license.txt

# import frappe
import frappe
from frappe.model.document import Document
from erpnext.stock.get_item_details import get_item_details
from erpnext.accounts.party import get_party_details
from frappe.utils import today


class SimpleSubscriptionItem(Document):
pass
@property
def current_rate(self):
parent = frappe.get_doc("Simple Subscription", self.parent)
currency = parent.currency or frappe.get_cached_value(
"Company", parent.company, "default_currency"
)

party_details = get_party_details(
party=parent.customer,
account=None,
party_type="Customer",
company=parent.company,
posting_date=today(),
currency=currency,
doctype="Sales Invoice",
fetch_payment_terms_template=False,
)

price_list = (
party_details.selling_price_list
or frappe.db.get_single_value("Selling Settings", "selling_price_list")
or frappe.db.get_value(
"Price List", {"selling": 1, "currency": currency, "enabled": 1}
)
)

item_details = get_item_details(
{
"item_code": self.item,
"company": parent.company,
"doctype": "Sales Invoice",
"currency": currency,
"price_list_currency": currency,
"qty": self.qty,
"plc_conversion_rate": 1,
"conversion_rate": 1,
"customer": parent.customer,
"transaction_date": today(),
"price_list": price_list,
}
)
return item_details.price_list_rate - (item_details.discount_amount or 0)

@property
def current_description(self):
return frappe.db.get_value("Item", self.item, "description")

@property
def item_name(self):
return frappe.db.get_value("Item", self.item, "item_name")

0 comments on commit 1fbc582

Please sign in to comment.