def get_all_calibration(): sql_text = ''' SELECT bi.id, si.id as stock_id, bi.buy_date, BRAND_NAME, MODEL_NAME, di.value_desc, si.balance, bi.number, si.total_cost, bi.total, ad.userName, bi.note, dic.value_desc FROM stock_info si,buy_info bi, Admin ad, stock_detail sd, dictionary di, dictionary dic WHERE si.id=bi.stock_id AND bi.buy_type= {} AND si.create_op = ad.id AND sd.changed_id = bi.id AND sd.stock_id = si.id AND sd.type in ({},{}) AND dic.key_id = bi.state AND dic.group_name = 'buy_state' AND di.key_id = sd.type AND di.group_name = 'stock_type\'''' \ .format(BuyInfo.calibrated(), StockDetail.by_decreased(), StockDetail.by_increased()) result = execute(sql_text) return result
def _submit(self): money_changed = self.money_changed.text() balance_changed = self.balance_changed.text() if not money_changed or not balance_changed: QMessageBox.information(self.addButton, '提示', '调整金额和调整数量不能为空!') self.balance_changed.setFocus() return money_changed = Decimal(money_changed) balance_changed = int(balance_changed) if money_changed == self.original_cost and balance_changed == self.original_balance: QMessageBox.information(self.addButton, '提示', '金额和数量未做调整,请重新填写!') self.balance_changed.setFocus() return changed_number = balance_changed - self.original_balance changed_cost = money_changed - self.original_cost buy_date = self.calibration_date.date().toString('yyyy-MM-dd') payment_method = list(Payment.get_payment_method().keys())[0] note = self.notes.text() create_op = int(self.staffComb.currentData()) try: db_transaction_util.begin() logger.info('新增库存校准数据') buy_id = buy_service.add_buy_info(self.stock_id, 9999, 0.0, changed_number, buy_date, 0.0, 0.0, changed_cost, payment_method, note, 0, create_op, BuyInfo.calibrated(), BuyInfo.under_reviewed()) if changed_number >= 0: change_type = StockDetail.by_increased() else: change_type = StockDetail.by_decreased() stock_service.add_stock_detail(self.stock_id, buy_id, abs(changed_cost), abs(changed_number), change_type) db_transaction_util.commit() logger.info('库存校准数据新增完成') QMessageBox.information(self.addButton, '提示', '库存校准成功,请等待数据审核!') self.close() except Exception as e: db_transaction_util.rollback() logger.error(e) logger.error('traceback.format_exc():\n{}'.format( traceback.format_exc()))
def do_review(self): review_id = table_utils.get_table_current_index_info(self.tableView, 0) if not review_id: QMessageBox.information(self.reviewButton, '提示', '请选择待审核的库存校准数据!') return stock_id = int( table_utils.get_table_current_index_info(self.tableView, 1)) stock_detail = stock_detail_handler.get_calibration_detail_by_buy_id( review_id) changed_type = stock_detail['type'] answer = QMessageBox.information( self.reviewButton, '校准审核', '是否审核通过该项库存校准?', QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Yes) try: db_transaction_util.begin() if answer == QMessageBox.Yes: changed_cost = Decimal( table_utils.get_table_current_index_info( self.tableView, 9)) changed_number = int( table_utils.get_table_current_index_info( self.tableView, 7)) if changed_type == StockDetail.by_decreased(): buy_service.decrease_buy_left(stock_id, abs(changed_number)) else: buy_service.increase_buy_left(stock_id, abs(changed_number)) stock_handler.update_stock_balance(stock_id, changed_number, changed_cost) buy_handler.update_buy_state(review_id, BuyInfo.normal()) elif answer == QMessageBox.No: buy_handler.update_buy_state(review_id, BuyInfo.rejected()) db_transaction_util.commit() self._init_table() except Exception as e: db_transaction_util.rollback() logger.error(e) logger.error('traceback.format_exc():\n{}'.format( traceback.format_exc()))
def get_calibration_detail_by_buy_id(buy_id: int): sql_text = ''' SELECT ID, STOCK_ID, changed_id, changed_money, changed_number, TYPE, UPDATE_TIME, UPDATE_OP FROM stock_detail WHERE changed_id = {} AND type in({},{}) order by id ''' \ .format(buy_id, StockDetail.by_increased(), StockDetail.by_decreased()) result = execute(sql_text, True) return result