Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
from enum import Enum

import frappe
from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice
from erpnext.accounts.party import get_party_details
from frappe import _
from frappe.model.document import Document

from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice
from frappe.utils import today


class Frequency(Enum):
Expand Down Expand Up @@ -47,6 +48,7 @@ def create_invoice(self, from_date: date, to_date: date) -> SalesInvoice:
invoice = frappe.new_doc("Sales Invoice")
invoice.company = self.company
invoice.customer = self.customer
invoice.selling_price_list = self.get_price_list()
for row in self.items:
invoice.append(
"items",
Expand All @@ -62,6 +64,28 @@ def create_invoice(self, from_date: date, to_date: date) -> SalesInvoice:
invoice.set_missing_values()
return invoice.insert()

def get_price_list(self) -> str | None:
currency = self.currency or frappe.get_cached_value("Company", self.company, "default_currency")

party_details = get_party_details(
party=self.customer,
account=None,
party_type="Customer",
company=self.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})
)

return price_list or None


@frappe.whitelist()
def create_current_invoice(subscription_name: str, silent=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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


Expand All @@ -16,24 +15,7 @@ def current_rate(self):
"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}
)
)
price_list = parent.get_price_list()

item_details = get_item_details(
{
Expand Down
Loading