Exemple #1
0
 def complete(self):
     purchase_order_id = self.request.matchdict.get('purchase_order_id')
     porder = PurchaseOrder.load(purchase_order_id)
     self.forbid_if(not porder or porder.company.enterprise_id != self.enterprise_id)
     porder.complete_dt = util.today()
     porder.save()
     for oitem in porder.order_items:
         if not oitem.complete_dt:
             oitem.complete_dt = util.today()
             oitem.save()
             InventoryJournal.create_new(oitem.product, 'Item Receipt', oitem.quantity)
     Status.add(None, porder, Status.find_event(self.enterprise_id, porder, 'COMPLETED'),
                'Purchase Order Completed', self.request.ctx.user) 
     return 'True'
Exemple #2
0
 def soft_delete(self):
     # If there is a delete_dt attribute, then set it to "now" and save it.
     self.invalidate_self()
     self.invalidate_caches()
     self.delete_dt = util.today()   #pylint: disable-msg=W0201
     self.save()
     return True
Exemple #3
0
 def find_by_product(product):
     return Session.query(Discount)\
         .join((DiscountProduct, DiscountProduct.discount_id == Discount.discount_id))\
         .filter(and_(DiscountProduct.product == product,
                      Discount.delete_dt == None,
                      or_(Discount.end_dt == None,
                          Discount.end_dt > util.today())))\
                          .order_by(Discount.create_dt.desc())\
                          .first()
Exemple #4
0
    def cancel(self, reason, by_customer=False):
        self.cancel_dt = datetime.datetime.date(datetime.datetime.now())
        for oitem in self.active_items:
            prod = oitem.product
            InventoryJournal.create_new(prod, "Cancelled Order", oitem.quantity, oitem)
            oitem.delete_dt = util.today()
            oitem.save()

        journals = Journal.find_all_by_order(self)
        for j in journals:
            j.delete_dt = util.today()
            j.save()

        msg = "Order Canceled" if not by_customer else "Order Cancelled by Customer"
        Status.add(
            self.customer,
            self,
            Status.find_event(self.customer.campaign.company.enterprise_id, self, "CREATED"),
            "%s : %s" % (msg, reason),
        )
        self.save()
Exemple #5
0
 def complete_item(self):
     purchase_order_id = self.request.matchdict.get('purchase_order_id')
     order_item_id = self.request.matchdict.get('order_item_id')
     porder = PurchaseOrder.load(purchase_order_id)
     self.forbid_if(not porder)
     poi = PurchaseOrderItem.load(order_item_id)
     self.forbid_if(not poi or poi.purchase_order != porder or poi.complete_dt)
     poi.complete_dt = util.today()
     poi.save()
     poi.flush()
     InventoryJournal.create_new(poi.product, 'Item Receipt', poi.quantity)
     Status.add(None, porder, Status.find_event(self.enterprise_id, porder, 'COMPLETED'),
                'Purchase Order Item "%s" Completed' % poi.product.name,
                self.request.ctx.user) 
     return 'True'
Exemple #6
0
    def return_item(self):
        customer_id = self.request.matchdict.get('customer_id')
        order_id = self.request.matchdict.get('order_id')
        order_item_id = self.request.matchdict.get('order_item_id')
        customer = Customer.load(customer_id)
        self.forbid_if(not customer or customer.campaign.company.enterprise_id != self.enterprise_id)
        order = customer.get_order(order_id)
        self.forbid_if(not order)
        order_item = OrderItem.load(order_item_id)
        self.forbid_if(not order_item or str(order_item.order.order_id) != str(order.order_id))
        user = self.request.ctx.user
        return_type = self.request.POST.get('rt_refund_type')
        quantity_returned = float(self.request.POST.get('quantity_returned'))
        credit_amount = float(self.request.POST.get('credit_amount'))

        jrnl = Journal.create_new(credit_amount, customer, order, user, return_type)
        ret = ProductReturn.create_new(order_item.product, order_item.order, quantity_returned, credit_amount, jrnl, user)
        status_note = "'%s' returned.  $%.2f refunded by %s" % (order_item.product.name, credit_amount, return_type)
        Status.add(customer, order_item, Status.find_event(self.enterprise_id, order_item, 'RETURN'), status_note)

        order_item.quantity -= quantity_returned
        if order_item.quantity == 0:
            order_item.delete_dt = util.today()
        order_item.save()
        if order_item.product.track_inventory:
            InventoryJournal.create_new(order_item.product, 'Return', quantity_returned, order_item, None, None, ret)

        for attr_kid in order_item.children:
            Status.add(customer, attr_kid, Status.find_event(self.enterprise_id, attr_kid, 'RETURN'), status_note)
            attr_kid_prod = attr_kid.product
            if attr_kid_prod.track_inventory:
                InventoryJournal.create_new(attr_kid_prod, 'Return', quantity_returned, attr_kid)

        self.flash(status_note)
        if len(order.active_items) == 0:
            # KB: [2012-09-06]: Deleted the one thing out of this
            # order.  Kill the order
            status_note = 'Only item in order returned. Order cancelled.'
            self._cancel_order_impl(order_id, status_note, False)
            self.flash(status_note)
            ret = HTTPFound('/crm/customer/show_orders/%s' % customer_id)
        else:
            ret = HTTPFound('/crm/customer/edit_order_dialog/%s/%s' % (customer_id, order_id))
        customer.invalidate_caches()
        return ret
Exemple #7
0
 def test_util(self):
     d8e = util.today_date()
     dtime = util.today()
     assert util.format_rss_date(d8e) == d8e.strftime("%a, %d %b %Y %H:%M:%S EST")
     assert util.words_date(dtime) == dtime.strftime("%B %d, %Y")
     assert util.is_empty(" ") == True
     assert util.float_("8") == None
     assert util.page_list([1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 2) == [3, 4]
     assert util.page_list([1, 2, 3, 4, 5, 6, 7, 8, 9], None, None) == [1, 2, 3, 4, 5, 6, 7, 8, 9]
     assert util.parse_date("2012-05-06") == datetime.datetime.strptime("2012-05-06", "%Y-%m-%d")
     today_ = datetime.date.today()
     assert [today_.year + 10, today_.year + 10] in util.year_list()
     assert util.month_list()[0] == ["1", "January"]
     assert util.this_year() == datetime.date.today().year
     assert util.get_first_day(today_) == util.get_first_day(
         today_
     )  # this is pretty dumb.  it works, just get it covered.
     assert util.get_last_day(today_) == util.get_last_day(today_)
     assert util.to_uuid("ken") == None
     assert int(util.average([1, 2, 3])) == 2
     assert util.format_date(util.truncate_datetime(dtime)) == util.str_today()
     assert util.is_today(d8e) == True
Exemple #8
0
    def test_dates(self):
        d8e = util.today_date()
        dtime = util.today()
        assert h.is_today(d8e)
        assert h.str_today() == util.str_today()
        assert h.date_time(None) == ''
        assert h.date_time(d8e) == d8e.strftime("%Y-%m-%d %H:%M:%S")
        assert h.date_(None) == ''
        assert h.date_(d8e) == d8e.strftime("%Y-%m-%d")
        assert h.format_date(None) == ''
        assert h.format_date(d8e) == d8e.strftime("%Y-%m-%d")
        assert h.words_date_time(None) == ''
        assert h.words_date_time(dtime) == dtime.strftime("%B %d, %Y at %I:%M %p")
        assert h.slash_date(None) == ''
        assert h.slash_date(dtime) == dtime.strftime("%m/%d/%Y")
        assert h.words_date(None) == ''
        assert h.words_date(dtime) == dtime.strftime("%B %d, %Y")
        assert h.this_year() == datetime.date.today().year
        self.assertEqual('checkbox' in h.chkbox('fud'), True)

        dobj = TestObj()
        assert h.get(dobj, 'a') == 'aa'
        assert h.get(dobj, 'bogus') == ''
Exemple #9
0
from pvscore.tests import TestController, secure
from pvscore.model.crm.appointment import Appointment
import pvscore.lib.util as util

# T pvscore.tests.controllers.test_crm_appointment

YESTERDAY = util.yesterday()
TODAY = util.today()
TOMORROW = util.tomorrow()


class TestCrmAppointment(TestController):
    @secure
    def test_show_new(self):
        R = self.get("/crm/appointment/new")
        assert R.status_int == 200
        R.mustcontain("New Appointment")
        f = R.forms["frm_appointment"]
        self.assertEqual(f["title"].value, "")

    def _create_new(self):
        # create the appointment and ensure he's editable.
        R = self.get("/crm/appointment/new")
        assert R.status_int == 200
        R.mustcontain("New Appointment")
        f = R.forms["frm_appointment"]
        self.assertEqual(f["appointment_id"].value, "")
        f.set("title", "Test Appointment")
        f.set("phone", "9041234567")
        f.set("description", "Test Description")
        f.set("start_dt", util.format_date(TOMORROW))