Beispiel #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))
Beispiel #2
0
    def save_new(self):
        try:
            obj = Customer(
                            no = _g('no'),
                            name = _g('name'),
                            display_name = _g('display_name'),
                            province_id = _g('province_id'),
                            city_id = _g('city_id'),
                            address = _g('address'),
                            contact_person = _g('contact_person'),
                            mobile = _g('mobile'),
                            phone = _g('phone'),
                            email = _g('email'),
                            remark = _g('remark'),
                            note_id = _g('note_id'),
#                            payment_id = _g('payment_id'),
                                )
            DBSession.add(obj)
            obj.attachment = multiupload()
            DBSession.commit()
            flash(MSG_SAVE_SUCC, MESSAGE_INFO)
            return redirect(url_for('.view', action = 'view', id = obj.id))
        except:
            _error(traceback.print_exc())
            DBSession.rollback()
            flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
            return redirect(url_for('.view'))
Beispiel #3
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))
Beispiel #4
0
    def save_new(self):
        try:
            params = {}
            for k in ['customer_id', 'order_time',
                      'source_province_id', 'source_city_id', 'destination_province_id', 'destination_city_id',
                      'source_company_id', 'source_address', 'source_contact', 'source_tel', 'source_mobile',
                      'destination_company_id', 'destination_address', 'destination_contact', 'destination_tel', 'destination_mobile',
                      'ref_no', 'estimate_time', 'expect_time', 'actual_time', 'remark',
                      'payment_id', 'pickup_type_id', 'pack_type_id', 'qty', 'qty_ratio', 'vol', 'vol_ratio',
                      'weight', 'weight_ratio', 'weight_ratio', 'amount', 'insurance_charge', 'sendout_charge', 'receive_charge',
                      'package_charge', 'other_charge', 'load_charge', 'unload_charge', 'proxy_charge', 'note_id', 'note_no',
                      'source_sms', 'destination_sms',
                      ]:
                params[k] = _g(k)
            order = OrderHeader(**params)
            DBSession.add(order)
            DBSession.flush()

            no = _g('no')
            b = Barcode.getOrCreate(no, order.ref_no)
            order.barcode = b.img
            order.no = b.value
            b.status = 0  # mark the barcode is use

            DBSession.add(TransferLog(
                                      refer_id = order.id,
                                      transfer_date = dt.now().strftime(SYSTEM_DATETIME_FORMAT),
                                      type = 0,
                                      remark = LOG_CREATE_ORDER,
                                      ))

            item_json = _g('item_json', '')
            for item in json.loads(item_json):
                DBSession.add(ItemDetail(
                                         header = order, item_id = item['item_id'], qty = item['qty'] or None,
                                         vol = item['vol'] or None, weight = item['weight'] or None,
                                         remark = item['remark'] or None
                                         ))


            # handle the upload file
            order.attachment = multiupload()

            # add the contact to the master
            try:
                DBSession.query(CustomerContact).filter(and_(
                                                         CustomerContact.active == 0,
                                                         CustomerContact.type == "S",
                                                         CustomerContact.refer_id == order.source_company_id,
                                                         CustomerContact.name == order.source_contact
                                                         )).one()
            except:
                # can't find the persons in source's contacts
                DBSession.add(CustomerContact(
                                              customer_id = order.customer_id,
                                              type = "S",
                                              refer_id = order.source_company_id,
                                              name = order.source_contact,
                                              address = order.source_address,
                                              phone = order.source_tel,
                                              mobile = order.source_mobile
                                              ))


            # add the contact to the master
            try:
                DBSession.query(CustomerContact).filter(and_(
                                                         CustomerContact.active == 0,
                                                         CustomerContact.type == "T",
                                                         CustomerContact.refer_id == order.destination_company_id,
                                                         CustomerContact.name == order.destination_contact
                                                         )).one()
            except:
                # can't find the persons in des's contacts
                DBSession.add(CustomerContact(
                                              customer_id = order.customer_id,
                                              type = "T",
                                              refer_id = order.destination_company_id,
                                              name = order.destination_contact,
                                              address = order.destination_address,
                                              phone = order.destination_tel,
                                              mobile = order.destination_mobile
                                              ))
            DBSession.commit()



            flash(MSG_SAVE_SUCC, MESSAGE_INFO)
            return redirect(url_for('.view', action = 'review', id = order.id))
        except:
            _error(traceback.print_exc())
            flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
            DBSession.rollback()
            return redirect(self.default())
Beispiel #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())
Beispiel #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())