Beispiel #1
0
	def before_save(self):
		has_expiry_date, shelf_life_in_days = dataent.db.get_value('Item', self.item, ['has_expiry_date', 'shelf_life_in_days'])
		if not self.expiry_date and has_expiry_date and shelf_life_in_days:
			self.expiry_date = add_days(self.manufacturing_date, shelf_life_in_days)

		if has_expiry_date and not self.expiry_date:
			dataent.throw(_('Expiry date is mandatory for selected item'))
			dataent.msgprint(_('Set items shelf life in days, to set expiry based on manufacturing_date plus self life'))
Beispiel #2
0
    def test_create_subscription_trial_with_wrong_dates(self):
        subscription = dataent.new_doc('Subscription')
        subscription.customer = '_Test Customer'
        subscription.trial_period_end = nowdate()
        subscription.trial_period_start = add_days(nowdate(), 30)
        subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})

        self.assertRaises(dataent.ValidationError, subscription.save)
        subscription.delete()
Beispiel #3
0
    def test_create_subscription_with_trial_with_correct_period(self):
        subscription = dataent.new_doc('Subscription')
        subscription.customer = '_Test Customer'
        subscription.trial_period_start = nowdate()
        subscription.trial_period_end = add_days(nowdate(), 30)
        subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
        subscription.save()

        self.assertEqual(subscription.trial_period_start, nowdate())
        self.assertEqual(subscription.trial_period_end,
                         add_days(nowdate(), 30))
        self.assertEqual(subscription.trial_period_start,
                         subscription.current_invoice_start)
        self.assertEqual(subscription.trial_period_end,
                         subscription.current_invoice_end)
        self.assertEqual(subscription.invoices, [])
        self.assertEqual(subscription.status, 'Trialling')

        subscription.delete()
Beispiel #4
0
    def is_past_grace_period(self):
        """
		Returns `True` if the grace period for the `Subscription` has passed
		"""
        current_invoice = self.get_current_invoice()
        if self.current_invoice_is_past_due(current_invoice):
            subscription_settings = dataent.get_single('Subscription Settings')
            grace_period = cint(subscription_settings.grace_period)

            return getdate(nowdate()) > add_days(current_invoice.due_date,
                                                 grace_period)
Beispiel #5
0
    def create_invoice(self, prorate):
        """
		Creates a `Sales Invoice`, submits it and returns it
		"""
        invoice = dataent.new_doc('Sales Invoice')
        invoice.set_posting_time = 1
        invoice.posting_date = self.current_invoice_start
        invoice.customer = self.customer

        # Subscription is better suited for service items. I won't update `update_stock`
        # for that reason
        items_list = self.get_items_from_plans(self.plans, prorate)
        for item in items_list:
            invoice.append('items', item)

        # Taxes
        if self.tax_template:
            invoice.taxes_and_charges = self.tax_template
            invoice.set_taxes()

        # Due date
        invoice.append(
            'payment_schedule', {
                'due_date':
                add_days(self.current_invoice_end, cint(self.days_until_due)),
                'invoice_portion':
                100
            })

        # Discounts
        if self.additional_discount_percentage:
            invoice.additional_discount_percentage = self.additional_discount_percentage

        if self.additional_discount_amount:
            invoice.discount_amount = self.additional_discount_amount

        if self.additional_discount_percentage or self.additional_discount_amount:
            discount_on = self.apply_additional_discount
            invoice.apply_additional_discount = discount_on if discount_on else 'Grand Total'

        # Subscription period
        invoice.from_date = self.current_invoice_start
        invoice.to_date = self.current_invoice_end

        invoice.flags.ignore_mandatory = True
        invoice.save()
        invoice.submit()

        return invoice
Beispiel #6
0
    def process_for_past_due_date(self):
        """
		Called by `process` if the status of the `Subscription` is 'Past Due Date'.

		The possible outcomes of this method are:
		1. Change the `Subscription` status to 'Active'
		2. Change the `Subscription` status to 'Cancelled'
		3. Change the `Subscription` status to 'Unpaid'
		"""
        current_invoice = self.get_current_invoice()
        if not current_invoice:
            dataent.throw(
                _('Current invoice {0} is missing'.format(
                    current_invoice.invoice)))
        else:
            if self.is_not_outstanding(current_invoice):
                self.status = 'Active'
                self.update_subscription_period(
                    add_days(self.current_invoice_end, 1))
            else:
                self.set_status_grace_period()