示例#1
0
    def get_items_from_plans(self, plans, prorate=0):
        """
		Returns the `Item`s linked to `Subscription Plan`
		"""
        if prorate:
            prorate_factor = get_prorata_factor(self.current_invoice_end,
                                                self.current_invoice_start)

        items = []
        customer = self.customer
        for plan in plans:
            item_code = frappe.db.get_value("Subscription Plan", plan.plan,
                                            "item")
            if not prorate:
                items.append({
                    'item_code':
                    item_code,
                    'qty':
                    plan.qty,
                    'rate':
                    get_plan_rate(plan.plan, plan.qty, customer)
                })
            else:
                items.append({
                    'item_code':
                    item_code,
                    'qty':
                    plan.qty,
                    'rate': (get_plan_rate(plan.plan, plan.qty, customer) *
                             prorate_factor)
                })

        return items
示例#2
0
def get_items_from_plans(customer, plans, prorate=0):
    print('88888888888888')
    if prorate:
        prorate_factor = get_prorata_factor(customer.current_invoice_end,
                                            customer.current_invoice_start)

    items = []
    customer = customer.customer
    for plan in plans:
        item_code = frappe.db.get_value("Subscription Plan", plan.plan, "item")
        if not prorate:
            items.append({
                'item_code': item_code,
                'qty': plan.qty,
                'rate': get_plan_rate(plan.plan, plan.qty, customer)
            })
        else:
            items.append({
                'item_code':
                item_code,
                'qty':
                plan.qty,
                'rate':
                (get_plan_rate(plan.plan, plan.qty, customer) * prorate_factor)
            })

    return items
示例#3
0
	def get_items_from_plans(self, plans, prorate=0):
		"""
		Returns the `Item`s linked to `Subscription Plan`
		"""
		if prorate:
			prorate_factor = get_prorata_factor(self.current_invoice_end, self.current_invoice_start,
				self.generate_invoice_at_period_start)

		items = []
		party = self.party
		for plan in plans:
			plan_doc = frappe.get_doc('Subscription Plan', plan.plan)

			item_code = plan_doc.item

			if self.party == 'Customer':
				deferred_field = 'enable_deferred_revenue'
			else:
				deferred_field = 'enable_deferred_expense'

			deferred = frappe.db.get_value('Item', item_code, deferred_field)

			if not prorate:
				item = {'item_code': item_code, 'qty': plan.qty, 'rate': get_plan_rate(plan.plan, plan.qty, party,
					self.current_invoice_start, self.current_invoice_end), 'cost_center': plan_doc.cost_center}
			else:
				item = {'item_code': item_code, 'qty': plan.qty, 'rate': get_plan_rate(plan.plan, plan.qty, party,
					self.current_invoice_start, self.current_invoice_end, prorate_factor), 'cost_center': plan_doc.cost_center}

			if deferred:
				item.update({
					deferred_field: deferred,
					'service_start_date': self.current_invoice_start,
					'service_end_date': self.current_invoice_end
				})

			accounting_dimensions = get_accounting_dimensions()

			for dimension in accounting_dimensions:
				if plan_doc.get(dimension):
					item.update({
						dimension: plan_doc.get(dimension)
					})

			items.append(item)

		return items
示例#4
0
	def get_items_from_plans(self, plans, prorate=0):
		"""
		Returns the `Item`s linked to `Subscription Plan`
		"""
		if prorate:
			prorate_factor = get_prorata_factor(self.current_invoice_end, self.current_invoice_start)

		items = []
		customer = self.customer
		for plan in plans:
			item_code = frappe.db.get_value("Subscription Plan", plan.plan, "item")
			if not prorate:
				items.append({'item_code': item_code, 'qty': plan.qty, 'rate': get_plan_rate(plan.plan, plan.qty, customer)})
			else:
				items.append({'item_code': item_code, 'qty': plan.qty, 'rate': (get_plan_rate(plan.plan, plan.qty, customer) * prorate_factor)})

		return items
示例#5
0
	def validate_subscription_details(self):
		if self.is_a_subscription:
			amount = 0
			for subscription_plan in self.subscription_plans:
				payment_gateway = frappe.db.get_value("Subscription Plan", subscription_plan.plan, "payment_gateway")
				if payment_gateway != self.payment_gateway_account:
					frappe.throw(_('The payment gateway account in plan {0} is different from the payment gateway account in this payment request'.format(subscription_plan.name)))

				rate = get_plan_rate(subscription_plan.plan, quantity=subscription_plan.qty)

				amount += rate

			if amount != self.grand_total:
				frappe.msgprint(_("The amount of {0} set in this payment request is different from the calculated amount of all payment plans: {1}. Make sure this is correct before submitting the document.".format(self.grand_total, amount)))
示例#6
0
	def validate_subscription_details(self):
		if self.is_a_subscription:
			amount = 0
			for subscription_plan in self.subscription_plans:
				payment_gateway = frappe.db.get_value("Subscription Plan", subscription_plan.plan, "payment_gateway")
				if payment_gateway != self.payment_gateway_account:
					frappe.throw(_('The payment gateway account in plan {0} is different from the payment gateway account in this payment request'.format(subscription_plan.name)))

				rate = get_plan_rate(subscription_plan.plan, quantity=subscription_plan.qty)

				amount += rate

			if amount != self.grand_total:
				frappe.msgprint(_("The amount of {0} set in this payment request is different from the calculated amount of all payment plans: {1}. Make sure this is correct before submitting the document.".format(self.grand_total, amount)))
示例#7
0
    def get_items_from_plans(self, plans, prorate=0):
        """
		Returns the `Item`s linked to `Subscription Plan`
		"""
        if prorate:
            prorate_factor = get_prorata_factor(
                self.current_invoice_end, self.current_invoice_start,
                self.generate_invoice_at_period_start)

        items = []
        party = self.party
        for plan in plans:
            plan_doc = frappe.get_doc("Subscription Plan", plan.plan)

            item_code = plan_doc.item

            if self.party == "Customer":
                deferred_field = "enable_deferred_revenue"
            else:
                deferred_field = "enable_deferred_expense"

            deferred = frappe.db.get_value("Item", item_code, deferred_field)

            if not prorate:
                item = {
                    "item_code":
                    item_code,
                    "qty":
                    plan.qty,
                    "rate":
                    get_plan_rate(plan.plan, plan.qty, party,
                                  self.current_invoice_start,
                                  self.current_invoice_end),
                    "cost_center":
                    plan_doc.cost_center,
                }
            else:
                item = {
                    "item_code":
                    item_code,
                    "qty":
                    plan.qty,
                    "rate":
                    get_plan_rate(
                        plan.plan,
                        plan.qty,
                        party,
                        self.current_invoice_start,
                        self.current_invoice_end,
                        prorate_factor,
                    ),
                    "cost_center":
                    plan_doc.cost_center,
                }

            if deferred:
                item.update({
                    deferred_field: deferred,
                    "service_start_date": self.current_invoice_start,
                    "service_end_date": self.current_invoice_end,
                })

            accounting_dimensions = get_accounting_dimensions()

            for dimension in accounting_dimensions:
                if plan_doc.get(dimension):
                    item.update({dimension: plan_doc.get(dimension)})

            items.append(item)

        return items