示例#1
0
    def post_save(self, obj, data, create_new=False):

        if obj.id:

            items = data["items"] if "items" in data else []

            for item in items:
                ReturnService.set_count_by_id(item["id"], item["count"])

        super(ReturnCanon, self).post_save(obj, data, create_new=create_new)
示例#2
0
    def handle(self, provider, mail):
        from applications.return_app.service import ReturnService
        from db import db
        return_inst = ReturnService.create_return(date_start=self.date_from, date_end=self.date_to, provider_id=provider.id)

        products = self.get_products()
        mail.return_item = return_inst
        db.session.add(mail)

        for product in products:
            ReturnService.handle_returnitem(
                full_name=product.full_name, name=product.name, number_local=product.number_local,
                number_global=product.number_global, date=product.date, date_to=product.date_to,
                price_without_NDS=product.price_without_NDS, price_with_NDS=product.price_with_NDS,
                remission=product.remission, count_delivery=product.count_delivery, count_rem=product.count_rem,
                return_inst=return_inst)
示例#3
0
    def status(cls, waybillreturn, status):
        from applications.point_sale.service import PointSaleService
        from applications.return_app.service import ReturnService
        debug(u"Смена статуса `накладной возврата` %s с %s на %s." % (
            waybillreturn.id, waybillreturn.status, StatusType[status]))

        if status == DRAFT:
            waybillreturn.items.delete()

        if status == IN_PROG:
            waybillreturn.items.delete()
            return_inst = ReturnService.get_by_id(waybillreturn.returninst_id)
            point = waybillreturn.pointsale

            for item in return_inst.items:
                good_id = item.good_id
                res = PointSaleService.item_to_pointsale_good(
                    point.id, good_id)
                if res:
                    itemreturn = WayBillReturnItems()
                    itemreturn.waybill = waybillreturn
                    itemreturn.good_id = good_id
                    itemreturn.count_plan = res.count
                    db.session.add(itemreturn)

        if status == FINISH:
            from_point = waybillreturn.pointsale
            to_point = PointSaleService.get_central()
            for item in waybillreturn.items:
                PointSaleService.sync_good_increment(
                    from_point.id, item.good_id, item.count * -1 if item.count
                    else 0)
                PointSaleService.sync_good_increment(
                    to_point.id, item.good_id, item.count if item.count else 0)

        waybillreturn.status = status
        debug(u"Смена статуса `накладной возврата` %s с %s на %s завершено." % (
            waybillreturn.id, waybillreturn.status, StatusType[status]))