Exemplo n.º 1
0
    def save_update(self):
        id = _g('id', None)
        if not id :
            flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
            return redirect(url_for('.view'))
        obj = DBSession.query(Customer).get(id)
        if not obj :
            flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR)
            return redirect(url_for('.view'))
        try:
            fields = ['no', 'name', 'display_name', 'province_id', 'city_id',
                      'address', 'contact_person', 'mobile', 'phone', 'email', 'note_id', 'remark']
            old_info = obj.serialize(fields) # to used for the history log
            for f in fields:
                setattr(obj, f, _g(f))

            #handle the file upload
            old_attachment_ids = map(lambda (k, v) : v, _gp("old_attachment_"))
            old_attachment_ids.extend(multiupload())
            obj.attachment = old_attachment_ids

            DBSession.commit()
            flash(MSG_SAVE_SUCC, MESSAGE_INFO)
#            return redirect(url_for('.view',id=obj.id))
            new_info = obj.serialize(fields)
            change_result = obj.compare(old_info, new_info)
            obj.insert_system_logs(change_result)
        except:
            _error(traceback.print_exc())
            DBSession.rollback()
            flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
        return redirect(url_for('.view', action = "view", id = obj.id))
Exemplo n.º 2
0
    def out_note_save_update(self):
        id = _g('id')
        if not id :
            flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
            return redirect(url_for(".view", action = "out_note"))
        obj = DBSession.query(InventoryOutNote).get(id)
        for f in ['customer_id', 'so', 'po', 'dn', 'ref', 'remark' ] : setattr(obj, f, _g(f))

        total_qty = total_weight = total_area = 0
        details_mapping = {}
        for d in obj.details : details_mapping['%s' % d.id] = d

        for qk, qv in _gp("qty_"):
            id = qk.split("_")[1]
            if id not in details_mapping : continue
            d = details_mapping[id]

            qty = self._p(_g('qty_%s' % id), int, 0)
            weight = self._p(_g('weight_%s' % id), float, 0)
            area = self._p(_g('area_%s' % id), float, 0)

            total_qty += qty
            total_area += area
            total_weight += weight

            if obj.status != 2:
                # update the locaion-item relation
                t = DBSession.query(InventoryLocationItem).filter(and_(InventoryLocationItem.location_id == d.location_id,
                                                                   InventoryLocationItem.item_id == d.item_id)).with_lockmode("update").one()

                if obj.status == 1:  # if the record is approved,update the real qty/weight/area
                    t.qty -= qty - d.qty
                    t.weight -= weight - d.weight
                    t.area -= area - d.area
                t.exp_qty -= qty - d.qty
                t.exp_weight -= weight - d.weight
                t.exp_area -= area - d.area

            d.qty = qty
            d.weight = weight
            d.area = area

        obj.qty = total_qty
        obj.area = total_area
        obj.weight = total_weight

        DBSession.commit()
        flash(MSG_UPDATE_SUCC, MESSAGE_INFO)
        return redirect(url_for(".view", action = "out_note_review", id = obj.id))
Exemplo n.º 3
0
    def out_note_save_new(self):
        params = {}
        for f in ["customer_id", "so", "po", "dn", "ref", "remark", ]: params[f] = _g(f)
        try:
            header = InventoryOutNote(**params)
            DBSession.add(header)
            DBSession.flush()
            total_qty = total_area = total_weight = 0
            for k, id in _gp("item_"):
                tmp_qty = int(_g('qty_%s' % id) or 0)
                tmp_area = float(_g('area_%s' % id) or 0)
                tmp_weight = float(_g('weight_%s' % id) or 0)

                total_qty += tmp_qty
                total_area += tmp_area
                total_weight += tmp_weight

                tmp_location_item = DBSession.query(InventoryLocationItem).get(id)
                tmp_location_item.exp_qty -= tmp_qty
                tmp_location_item.exp_area -= tmp_area
                tmp_location_item.exp_weight -= tmp_weight

                DBSession.add(InventoryNoteDetail(
                                                  header_id = header.id,
                                                  type = 'OUT',
                                                  item_id = tmp_location_item.item_id,
                                                  desc = tmp_location_item.item.desc,
                                                  qty = tmp_qty,
                                                  weight = tmp_weight,
                                                  area = tmp_area,
                                                  remark = _g('remark_%s' % id),
                                                  location_id = tmp_location_item.location_id,
                                                  ))
            header.qty = total_qty
            header.weight = total_weight
            header.area = total_area
            header.no = getOutNo(header.id)

            DBSession.commit()
            flash(MSG_SAVE_SUCC, MESSAGE_INFO)
            return redirect(url_for('.view', action = "out_note_review", id = header.id))
        except:
            DBSession.rollback()
            _error(traceback.print_exc())
            flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
            return redirect(url_for(".view", action = "index"))
Exemplo n.º 4
0
    def save_update(self):
        id = _g("id")
        if not id:
            flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
            return redirect(self.default())
        header = DBSession.query(OrderHeader).get(id)
        fields = [
                  'customer_id', 'order_time',
                  'source_province_id', 'source_city_id', 'destination_province_id', 'destination_city_id',
                  'ref_no', 'source_company_id', 'source_address', 'source_contact', 'source_tel', 'source_mobile',
                  'payment_id', 'qty', 'weight', 'vol', 'shipment_type_id',
                   'destination_company_id', 'destination_address', 'destination_contact', 'destination_tel', 'destination_mobile',
                  'estimate_time', 'expect_time', 'actual_time', 'qty_ratio', 'weight_ratio', 'vol_ratio', 'amount', 'cost', 'remark',
                  'pickup_type_id', 'pack_type_id',
                  'insurance_charge', 'sendout_charge', 'receive_charge', 'package_charge', 'other_charge', 'load_charge', 'unload_charge',
                  'proxy_charge', 'note_id', 'note_no',
                  'source_sms', 'destination_sms',
                  ]
        _remark = []
        old_info = header.serialize(fields)  # to used for the history log

        checkbox_fields = ['source_sms', 'destination_sms', ]
        try:
            for f in fields: setattr(header, f, _g(f))

            for f in checkbox_fields:
                vs = _gl(f)
                if vs : setattr(header, f, vs[0])
                else : setattr(header, f, None)
            no = _g('no')
            if no != header.no:
                try:
                    old_barcode = DBSession.query(Barcode).filter(Barcode.value == header.no).one()
                    old_barcode.status = 1  # mark the old barcode to be reserved
                except:
                    pass
                try:
                    new_barcode = DBSession.query(Barcode).filter(Barcode.value == no).one()
                    new_barcode.status = 0  # mark the new barcode to be used
                except NoResultFound :
                    DBSession.add(Barcode(value = no))
                except:
                    pass
                header.no = no
                header.barcode = generate_barcode_file(header.no)

            if header.status == -2 : header.status = 0

            item_ids = [c.id for c in header.item_details]
            item_json = _g('item_json', '')
            for c in json.loads(item_json):
                if not c.get('id', None) : continue
                if isinstance(c['id'], basestring) and c['id'].startswith("old_"):  # existing item
                    cid = c['id'].split("_")[1]
                    t = DBSession.query(ItemDetail).get(cid)
                    t.item_id = c.get('item_id', None)
                    t.qty = c.get('qty', None)
                    t.weight = c.get('weight', None)
                    t.vol = c.get('vol', None)
                    t.remark = c.get('remark', None)
                    item_ids.remove(t.id)
                else:
                    DBSession.add(ItemDetail(
                                                header = header,
                                                item_id = c.get('item_id', None),
                                                qty = c.get('qty', None),
                                                weight = c.get('weight', None),
                                                vol = c.get('vol', None),
                                                remark = c.get('remark', None),
                                                  ))

            DBSession.query(ItemDetail).filter(ItemDetail.id.in_(item_ids)).update({'active' : 1}, False)

            # handle the file upload
            old_attachment_ids = map(lambda (k, v) : v, _gp("old_attachment_"))
            old_attachment_ids.extend(multiupload())
            header.attachment = old_attachment_ids

            DBSession.commit()

            # handle the system log
            new_info = header.serialize(fields)
            change_result = header.compare(old_info, new_info)
            header.insert_system_logs(change_result)
            flash(MSG_UPDATE_SUCC, MESSAGE_INFO)
        except:
            _error(traceback.print_exc())
            DBSession.rollback()
            flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
        return redirect(url_for('.view', action = 'review', id = header.id))
Exemplo n.º 5
0
    def deliver_save_revise(self):
        id = _g('id')
        if not id :
            flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR)
            return redirect(self.default())

        try:
            header = DBSession.query(DeliverHeader).get(id)
            fields = [
                      'ref_no', 'destination_province_id', 'destination_city_id', 'destination_address', 'destination_contact',
                      'destination_tel', 'destination_mobile', 'supplier_id', 'supplier_contact', 'supplier_tel',
                      'need_transfer', 'amount', 'remark', 'expect_time', 'order_time',
                      'insurance_charge', 'sendout_charge', 'receive_charge', 'package_charge', 'other_charge', 'carriage_charge',
                      'load_charge', 'unload_charge', 'proxy_charge', 'payment_id', 'pickup_type_id',
                      'qty', 'weight', 'vol', 'qty_ratio', 'weight_ratio', 'vol_ratio', 'shipment_type_id',
                      ]

            _remark = []
            old_info = header.serialize(fields)  # to used for the history log
            for f in fields:    setattr(header, f, _g(f))

            total_qty = total_vol = total_weight = 0

            for d in header.details:
                d.qty = _g('qty_%s' % d.id)
                d.vol = _g('vol_%s' % d.id)
                d.weight = _g('weight_%s' % d.id)
                d.insurance_charge = _g('insurance_charge_%s' % d.id)
                d.sendout_charge = _g('sendout_charge_%s' % d.id)
                d.receive_charge = _g('receive_charge_%s' % d.id)
                d.package_charge = _g('package_charge_%s' % d.id)
                d.load_charge = _g('load_charge_%s' % d.id)
                d.unload_charge = _g('unload_charge_%s' % d.id)
                d.other_charge = _g('other_charge_%s' % d.id)
                d.proxy_charge = _g('proxy_charge_%s' % d.id)
                d.carriage_charge = _g('carriage_charge_%s' % d.id)
                d.amount = _g('amount_%s' % d.id)
                d.order_header.cost = d.amount

                if d.qty : total_qty += float(d.qty)
                if d.vol : total_vol += float(d.vol)
                if d.weight : total_weight += float(d.weight)


            header.qty = total_qty
            header.vol = total_vol
            header.weight = total_weight

            # handle the file upload
            old_attachment_ids = map(lambda (k, v) : v, _gp("old_attachment_"))
            old_attachment_ids.extend(multiupload())
            header.attachment = old_attachment_ids

            DBSession.commit()

            new_info = header.serialize(fields)
            change_result = header.compare(old_info, new_info)
            header.insert_system_logs(change_result)

            flash(MSG_SAVE_SUCC, MESSAGE_INFO)
        except:
            _error(traceback.print_exc())
            DBSession.rollback()
            flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
        return redirect(self.default())
Exemplo n.º 6
0
    def deliver_save_new(self):
        try:
            params = {}
            for f in ['ref_no', 'destination_province_id', 'destination_city_id', 'destination_address', 'destination_contact',
                      'destination_tel', 'destination_mobile', 'supplier_id',
                      'supplier_contact', 'supplier_tel', 'expect_time', 'order_time',
                      'insurance_charge', 'sendout_charge', 'receive_charge', 'package_charge', 'load_charge', 'unload_charge',
                      'other_charge', 'proxy_charge', 'amount', 'payment_id', 'pickup_type_id', 'remark', 'carriage_charge',
                      'qty', 'weight', 'vol', 'qty_ratio', 'weight_ratio', 'vol_ratio', 'shipment_type_id',
                      ]:
                params[f] = _g(f)
            header = DeliverHeader(**params)
            DBSession.add(header)
            DBSession.flush()
            header.no = getDeliverNo(header.id)
            total_qty = total_vol = total_weight = 0
            line_no = 1
            for k, id in _gp('detail_'):
                order_header = DBSession.query(OrderHeader).get(id)
                d = DeliverDetail(header = header,
                                            order_header = order_header,
                                            line_no = line_no,
                                            qty = _g('qty_%s' % id),
                                            vol = _g('vol_%s' % id),
                                            weight = _g('weight_%s' % id),
                                            insurance_charge = _g('insurance_charge_%s' % id),
                                            sendout_charge = _g('sendout_charge_%s' % id),
                                            receive_charge = _g('receive_charge_%s' % id),
                                            package_charge = _g('package_charge_%s' % id),
                                            load_charge = _g('load_charge_%s' % id),
                                            unload_charge = _g('unload_charge_%s' % id),
                                            other_charge = _g('other_charge_%s' % id),
                                            proxy_charge = _g('proxy_charge_%s' % id),
                                            carriage_charge = _g('carriage_charge_%s' % id),
                                            amount = _g('amount_%s' % id),
                                            )
                DBSession.add(d)
                if order_header.qty : total_qty += float(d.qty)
                if order_header.vol : total_vol += float(d.vol)
                if order_header.weight : total_weight += float(d.weight)

                order_header.update_status(SORTING[0])
                order_header.cost = _g('amount_%s' % id),
                order_header.deliver_header_ref = header.id
                order_header.deliver_header_no = header.ref_no
                line_no += 1

            header.qty = total_qty
            header.vol = total_vol
            header.weight = total_weight

            DBSession.add(TransferLog(
                                      refer_id = header.id,
                                      transfer_date = dt.now().strftime(SYSTEM_DATETIME_FORMAT),
                                      type = 1,
                                      remark = LOG_GOODS_SORTED
                                      ))

            # handle the upload file
            header.attachment = multiupload()
            DBSession.commit()
        except:
            DBSession.rollback()
            _error(traceback.print_exc())
            flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
            return redirect(self.default())
        else:
            flash(MSG_SAVE_SUCC, MESSAGE_INFO)
            return redirect(self.default())