Пример #1
0
    def order(self, user, po=None):
        """
        Purchase this Service Part
        """
        if po is None:
            po = PurchaseOrder()
            po.location = user.get_location()
            po.sales_order = self.repair.order
            po.reference = self.repair.reference
            po.confirmation = self.repair.confirmation
            po.created_by = user
            po.supplier = "Apple"
            po.save()

        self.purchase_order = po
        poi = PurchaseOrderItem(purchase_order=po)
        poi.code = self.part_number
        poi.title = self.part_title
        poi.order_item = self.order_item
        poi.product = self.order_item.product
        poi.price = self.order_item.get_purchase_price()

        poi.save()

        if po.submitted_at is None:
            po.submit(user)

        self.save()
Пример #2
0
    def submit(self, customer_data):
        """
        Creates a new GSX repair and all the documentation that goes along with it
        """
        if len(self.parts.all()) < 1:
            raise ValueError(_("Please add some parts to the repair"))

        if not self.order.queue:
            raise ValueError(_("Order has not been assigned to a queue"))

        
        repair_data = self.to_gsx()

        if self.repair_type == "CA":
            gsx_repair = gsxws.CarryInRepair(**repair_data)
        if self.repair_type == "ON":
            gsx_repair = gsxws.IndirectOnsiteRepair(**repair_data)

        customer_data['regionCode'] = self.gsx_account.region
        gsx_repair.customerAddress = gsxws.Customer(**customer_data)

        if self.component_data:
            ccd = []
            cd = json.loads(self.component_data)
            for k, v in cd.items():
                ccd.append(gsxws.ComponentCheck(component=k, serialNumber=v))

            gsx_repair.componentCheckDetails = ccd

        parts = [p.get_repair_order_line() for p in self.servicepart_set.all()]
        gsx_repair.orderLines = parts

        # Submit the GSX repair request
        result = gsx_repair.create()

        po = self.create_purchase_order()

        for p in self.servicepart_set.all():
            p.purchase_order = po
            p.created_by = self.created_by
            p.save()

            poi = PurchaseOrderItem.from_soi(po, p.order_item, self.created_by)
            poi.save()

        confirmation = result.confirmationNumber
        self.confirmation = confirmation
        self.submitted_at = timezone.now()

        po.confirmation = confirmation
        po.submit(self.created_by)

        self.save()

        msg = _(u"GSX repair %s created") % confirmation
        self.order.notify("gsx_repair_created", msg, self.created_by)

        if repair_data.get("markCompleteFlag") is True:
            self.close(self.created_by)
Пример #3
0
    def submit(self, customer_data):
        """
        Creates a new GSX repair and all the documentation that goes along with it
        """
        if len(self.parts.all()) < 1:
            raise ValueError(_("Please add some parts to the repair"))

        if not self.order.queue:
            raise ValueError(_("Order has not been assigned to a queue"))

        repair_data = self.to_gsx()

        if self.repair_type == "CA":
            gsx_repair = gsxws.CarryInRepair(**repair_data)
        if self.repair_type == "ON":
            gsx_repair = gsxws.IndirectOnsiteRepair(**repair_data)

        customer_data['regionCode'] = self.gsx_account.region
        gsx_repair.customerAddress = gsxws.Customer(**customer_data)

        if self.component_data:
            ccd = []
            cd = json.loads(self.component_data)
            for k, v in cd.items():
                ccd.append(gsxws.ComponentCheck(component=k, serialNumber=v))

            gsx_repair.componentCheckDetails = ccd

        parts = [p.get_repair_order_line() for p in self.servicepart_set.all()]
        gsx_repair.orderLines = parts

        # Submit the GSX repair request
        result = gsx_repair.create()

        po = self.create_purchase_order()

        for p in self.servicepart_set.all():
            p.purchase_order = po
            p.created_by = self.created_by
            p.save()

            poi = PurchaseOrderItem.from_soi(po, p.order_item, self.created_by)
            poi.save()

        confirmation = result.confirmationNumber
        self.confirmation = confirmation
        self.submitted_at = timezone.now()

        po.confirmation = confirmation
        po.submit(self.created_by)

        self.save()

        msg = _(u"GSX repair %s created") % confirmation
        self.order.notify("gsx_repair_created", msg, self.created_by)

        if repair_data.get("markCompleteFlag") is True:
            self.close(self.created_by)
Пример #4
0
    def mark_doa(self):
        """
        Marking a part DOA means we get a new part, so:
        - make a copy of the old part
        """
        # Update our PO so we know to expect the replacement for the DOA part
        poi = PurchaseOrderItem(price=0, purchase_order=self.purchase_order)
        poi.product = self.order_item.product
        poi.order_item = self.order_item
        poi.ordered_at = timezone.now()
        poi.save()

        # Create a copy of this part and reset
        new_part                = self
        new_part.pk             = None
        new_part.shipment       = None
        new_part.line_number    = None
        new_part.returned_at    = None

        new_part.return_order   = ''
        new_part.order_status   = ''
        new_part.return_label   = None
        new_part.order_status_code = ''
        new_part.coverage_description = ''
        new_part.registered_for_return = False

        new_part.save()