コード例 #1
0
 def handle(self, text):
     product_code, quantity = text.split()
     product_code = sub('m|M', '', product_code)
     if not product_code and quantity:
         self.respond(
             _("Sorry, invalid format.  The message should be in the format 'si <MSD product code> <amount>'"
               ))
         return
     else:
         sdp = self.msg.contact.contactdetail.service_delivery_point
         try:
             product = Product.get_product(product_code)
         except Product.DoesNotExist:
             self.respond(_("Sorry, invalid product code %(code)s"),
                          code=product_code.upper())
             return
         if not is_number(quantity):
             self.respond(
                 _("Sorry, invalid format.  The message should be in the format 'si <MSD product code> <amount>'"
                   ))
             return
         report_type = ProductReportType.objects.filter(
             sms_code='soh')[0:1].get()
         sdp.report_product_status(product=product,
                                   report_type=report_type,
                                   quantity=quantity,
                                   message=self.msg.logger_msg)
         self.respond(_(
             'Thank you, you reported you have %(quantity)s     %(product_name)s. If incorrect, please resend.'
         ),
                      product_name=product.name,
                      quantity=quantity)
コード例 #2
0
ファイル: stockinquiry.py プロジェクト: andile2012/logistics
 def handle(self, text):
     product_code, quantity = text.split()
     product_code = sub('m|M', '', product_code)
     if not product_code and quantity:
          self.respond(_("Sorry, invalid format.  The message should be in the format 'si <MSD product code> <amount>'"))
          return
     else:    
         sdp = self.msg.contact.contactdetail.service_delivery_point
         try:
             product = Product.get_product(product_code)   
         except Product.DoesNotExist:
             self.respond(_("Sorry, invalid product code %(code)s"), code=product_code.upper())
             return
         if not is_number(quantity):
             self.respond(_("Sorry, invalid format.  The message should be in the format 'si <MSD product code> <amount>'"))
             return
         report_type = ProductReportType.objects.filter(sms_code='soh')[0:1].get()
         sdp.report_product_status(product=product,report_type=report_type,quantity=quantity, message=self.msg.logger_msg)
         self.respond(_('Thank you, you reported you have %(quantity)s     %(product_name)s. If incorrect, please resend.'), product_name=product.name, quantity=quantity)        
コード例 #3
0
 def handle(self, text):
     service_delivery_point=self.msg.contact.contactdetail.service_delivery_point
     if service_delivery_point.service_delivery_point_type.name == "DISTRICT":
         st = ServiceDeliveryPointStatusType.objects.filter(short_name="delivery_received_district")[0:1].get()
         ns = ServiceDeliveryPointStatus(service_delivery_point=service_delivery_point, status_type=st, status_date=datetime.now())
         ns.save()
         kwargs={'contact_name': self.msg.contact.name,
                 'facility_name': service_delivery_point.name}
         self.respond(_('Thank you %(contact_name)s for reporting your delivery for %(facility_name)s'), **kwargs)
         self._send_delivery_alert_to_facilities(service_delivery_point)
     elif service_delivery_point.service_delivery_point_type.name == "FACILITY":
         product_list = text.split()
         if len(product_list) > 0 and len(product_list) % 2 != 0:
              self.respond(_("Sorry, invalid format.  The message should be in the format 'delivered product amount product amount'"))
              return
         else:
             reply_list = []
             while len(product_list) >= 2:
                 product_code = product_list.pop(0)
                 quantity = product_list.pop(0)
                 if not is_number(quantity):
                     if is_number(product_code):
                         temp = product_code
                         product_code = quantity
                         quantity = temp
                     else:                        
                         self.respond(_("Sorry, invalid format.  The message should be in the format 'delivered product amount product amount'"))
                         return
                 
                 report_type = ProductReportType.objects.filter(sms_code='dlvd')[0:1].get()
                 try:
                     product = Product.get_product(product_code)      
                 except Product.DoesNotExist:
                     self.respond(_('Sorry, invalid product code %(code)s'), code=product_code)
                     return
                 reply_list.append('%s %s' % (product.sms_code, quantity) )
                 service_delivery_point.report_product_status(product=product,report_type=report_type,quantity=quantity, message=self.msg.logger_msg)
             
             st = ServiceDeliveryPointStatusType.objects.filter(short_name="delivery_quantities_reported")[0:1].get()
             ns = ServiceDeliveryPointStatus(service_delivery_point=service_delivery_point, status_type=st, status_date=datetime.now())
             ns.save()
             self.respond(_('Thank you, you reported a delivery of %(reply_list)s. If incorrect, please resend.'), reply_list=','.join(reply_list))