def save(self, force_insert=False, force_update=False, using=None, update_fields=None): import decimal super(OfferSheet, self).save(force_insert, force_update, using, update_fields) if self.discount_amount > 0: sql = ( "UPDATE sale_offeritem a SET a.discount_price = a.sale_price - " "((SELECT discount_amount/amount FROM sale_offersheet WHERE id = %s) * (a.sale_price*a.cnt)/a.cnt) WHERE a.master_id = %s" ) params = [self.id, self.id] # print(sql % (self.id,self.id)) generic.update(sql, params) item_count = OfferItem.objects.filter(master=self).count() if self.attach and item_count == 0: path = os.path.join(settings.MEDIA_ROOT, self.attach.name) workbook = xlrd.open_workbook(path) sheet = workbook.sheet_by_index(0) row_count = sheet.nrows with transaction.atomic(): total_amount = decimal.Decimal(0) for row_index in range(row_count): row = sheet.row_values(row_index) if row_index == 0: doc_type = row[1] if doc_type.startswith("0"): break else: continue elif row_index < 3: continue material = None measure = None try: measure = Measure.objects.get(code=row[4]) except Exception as e: measure = Measure.objects.create(code=row[4], name=force_text(row[5])) try: material = Material.objects.get(code=row[0]) except Exception as e: material = Material(code=row[0], name=force_text(row[1]), spec=force_text(row[2])) material.sale_price = row[6] material.purchase_price = row[7] material.save() OfferItem.objects.create( master=self, material=material, measure=measure, cnt=row[8], brand=force_text(row[3]), cost_price=row[7], sale_price=row[6], ) total_amount += decimal.Decimal(row[6]) * decimal.Decimal(row[8]) sql = "update sale_offersheet set amount = %s where id=%s" params = [total_amount, self.id] generic.update(sql, params)
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): super(InitialInventory, self).save(force_insert, force_update, using, update_fields) count = InitItem.objects.filter(master=self).count() if self.attach and count == 0: path = os.path.join(settings.MEDIA_ROOT, self.attach.name) reader = csv.reader(open(path, 'r')) index = 0 with transaction.atomic(): for code, name, description, unit_code, unit_name, warehouse_code, warehouse_name, price, cnt in reader: index += 1 if index == 1: continue material = None measure = None house = None try: measure = Measure.objects.get(code=unit_code) except Exception as e: measure = Measure.objects.create( code=unit_code, name=force_text(unit_name.decode('gbk'))) try: house = Warehouse.objects.get(code=warehouse_code) except Exception as e: house = Warehouse.objects.create( code=warehouse_code, name=force_text(warehouse_name.decode('gbk'))) try: material = Material.objects.get(code=code) except Exception as e: material = Material( code=code, name=force_text(name.decode('gbk')), spec=force_text(description.decode('gbk')), warehouse=house) material.stock_price = price material.save() InitItem.objects.create(master=self, material=material, price=price, cnt=cnt, warehouse=house, measure=measure, source=self.code)
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): super(WorkOrder, self).save(force_insert, force_update, using, update_fields) if self.service: material = self.service if self.woextravalue_set.count( ) < 1 and material.extraparam_set and material.extraparam_set.count( ) > 0: for param in material.extraparam_set.all(): extra_param = WOExtraValue.objects.create(workorder=self, param_name=param) self.woextravalue_set.add(extra_param) item_count = WOItem.objects.filter(workorder=self).count() if self.detail and item_count == 0: path = os.path.join(settings.MEDIA_ROOT, self.detail.name) workbook = xlrd.open_workbook(path) sheet = workbook.sheet_by_index(0) row_count = sheet.nrows with transaction.atomic(): for row_index in range(row_count): row = sheet.row_values(row_index) if row_index == 0: doc_type = row[1] if doc_type.startswith('0'): break else: continue elif row_index < 3: continue material = None measure = None try: measure = Measure.objects.get(code=row[4]) except Exception as e: measure = Measure.objects.create(code=row[4], name=force_text( row[5])) try: material = Material.objects.get(code=row[0]) except Exception as e: material = Material(code=row[0], name=force_text(row[1]), spec=force_text(row[2])) material.save() WOItem.objects.create(workorder=self, material=material, measure=measure, amount=row[6])
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): super(InitialInventory, self).save(force_insert, force_update, using, update_fields) count = InitItem.objects.filter(master=self).count() if self.attach and count == 0: path = os.path.join(settings.MEDIA_ROOT, self.attach.name) reader = csv.reader(open(path, "r")) index = 0 with transaction.atomic(): for code, name, description, unit_code, unit_name, warehouse_code, warehouse_name, price, cnt in reader: index += 1 if index == 1: continue material = None measure = None house = None try: measure = Measure.objects.get(code=unit_code) except Exception as e: measure = Measure.objects.create(code=unit_code, name=force_text(unit_name.decode("gbk"))) try: house = Warehouse.objects.get(code=warehouse_code) except Exception as e: house = Warehouse.objects.create( code=warehouse_code, name=force_text(warehouse_name.decode("gbk")) ) try: material = Material.objects.get(code=code) except Exception as e: material = Material( code=code, name=force_text(name.decode("gbk")), spec=force_text(description.decode("gbk")), warehouse=house, ) material.stock_price = price material.save() InitItem.objects.create( master=self, material=material, price=price, cnt=cnt, warehouse=house, measure=measure, source=self.code, )
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): super(PurchaseOrder,self).save(force_insert,force_update,using,update_fields) if self.discount_amount > 0: sql = 'UPDATE purchase_poitem a SET a.discount_price = ' \ 'a.price-((SELECT discount_amount/amount FROM purchase_purchaseorder WHERE id=%s)*a.amount/a.cnt) WHERE a.po_id = %s' params = [self.id,self.id] generic.update(sql,params) item_count = POItem.objects.filter(po=self).count() if self.attach and item_count == 0: path = os.path.join(settings.MEDIA_ROOT,self.attach.name) workbook = xlrd.open_workbook(path) sheet = workbook.sheet_by_index(0) row_count = sheet.nrows with transaction.atomic(): total_amount = decimal.Decimal(0) for row_index in range(row_count): row = sheet.row_values(row_index) if row_index == 0: doc_type = row[1] if doc_type.startswith('0'): break else: continue elif row_index < 3: continue material = None measure = None try: measure = Measure.objects.get(code=row[4]) except Exception as e: measure = Measure.objects.create(code=row[4],name=force_text(row[5])) try: material = Material.objects.get(code=row[0]) except Exception as e: material = Material(code=row[0],name=force_text(row[1]),spec=force_text(row[2])) material.purchase_price = row[6] material.save() amount = decimal.Decimal(row[6])*decimal.Decimal(row[7]) POItem.objects.create(po=self,material=material,measure=measure,cnt=row[7],price=row[6],amount=amount) total_amount += amount sql = 'update purchase_purchaseorder set amount = %s where id=%s' params = [total_amount,self.id] generic.update(sql,params)
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): super(PurchaseOrder,self).save(force_insert,force_update,using,update_fields) if self.discount_amount > 0: sql = 'UPDATE purchase_poitem a SET a.discount_price = ' \ 'a.price-((SELECT discount_amount/amount FROM purchase_purchaseorder WHERE id=%s)*a.amount/a.cnt) WHERE a.po_id = %s' params = [self.id,self.id] generic.update(sql,params) item_count = POItem.objects.filter(po=self).count() if self.attach and item_count == 0: path = os.path.join(settings.MEDIA_ROOT,self.attach.name) workbook = xlrd.open_workbook(path) sheet = workbook.sheet_by_index(0) row_count = sheet.nrows with transaction.atomic(): total_amount = decimal.Decimal(0) for row_index in range(row_count): row = sheet.row_values(row_index) if row_index == 0: doc_type = row[1] if doc_type.startswith('0'): break else: continue elif row_index < 3: continue material = None measure = None try: measure = Measure.objects.get(code=row[4]) except Exception,e: measure = Measure.objects.create(code=row[4],name=force_text(row[5])) try: material = Material.objects.get(code=row[0]) except Exception,e: material = Material(code=row[0],name=force_text(row[1]),spec=force_text(row[2])) material.purchase_price = row[6] material.save() amount = decimal.Decimal(row[6])*decimal.Decimal(row[7]) POItem.objects.create(po=self,material=material,measure=measure,cnt=row[7],price=row[6],amount=amount) total_amount += amount sql = 'update purchase_purchaseorder set amount = %s where id=%s' params = [total_amount,self.id] generic.update(sql,params)
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): super(WorkOrder,self).save(force_insert,force_update,using,update_fields) if self.service: material = self.service if self.woextravalue_set.count() < 1 and material.extraparam_set and material.extraparam_set.count() > 0: for param in material.extraparam_set.all(): extra_param = WOExtraValue.objects.create(workorder=self,param_name=param) self.woextravalue_set.add(extra_param) item_count = WOItem.objects.filter(workorder=self).count() if self.detail and item_count == 0: path = os.path.join(settings.MEDIA_ROOT,self.detail.name) workbook = xlrd.open_workbook(path) sheet = workbook.sheet_by_index(0) row_count = sheet.nrows with transaction.atomic(): for row_index in range(row_count): row = sheet.row_values(row_index) if row_index == 0: doc_type = row[1] if doc_type.startswith('0'): break else: continue elif row_index < 3: continue material = None measure = None try: measure = Measure.objects.get(code=row[4]) except Exception as e: measure = Measure.objects.create(code=row[4],name=force_text(row[5])) try: material = Material.objects.get(code=row[0]) except Exception as e: material = Material(code=row[0],name=force_text(row[1]),spec=force_text(row[2])) material.save() WOItem.objects.create(workorder=self,material=material,measure=measure,amount=row[6])
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): import decimal super(OfferSheet,self).save(force_insert,force_update,using,update_fields) if self.discount_amount > 0: sql = 'UPDATE sale_offeritem a SET a.discount_price = a.sale_price - ' \ '((SELECT discount_amount/amount FROM sale_offersheet WHERE id = %s) * (a.sale_price*a.cnt)/a.cnt) WHERE a.master_id = %s' params = [self.id,self.id] # print sql % (self.id,self.id) generic.update(sql,params) item_count = OfferItem.objects.filter(master=self).count() if self.attach and item_count == 0: path = os.path.join(settings.MEDIA_ROOT,self.attach.name) workbook = xlrd.open_workbook(path) sheet = workbook.sheet_by_index(0) row_count = sheet.nrows with transaction.atomic(): total_amount = decimal.Decimal(0) for row_index in range(row_count): row = sheet.row_values(row_index) if row_index == 0: doc_type = row[1] if doc_type.startswith('0'): break else: continue elif row_index < 3: continue material = None measure = None try: measure = Measure.objects.get(code=row[4]) except Exception as e: measure = Measure.objects.create(code=row[4],name=force_text(row[5])) try: material = Material.objects.get(code=row[0]) except Exception as e: material = Material(code=row[0],name=force_text(row[1]),spec=force_text(row[2])) material.sale_price = row[6] material.purchase_price = row[7] material.save() OfferItem.objects.create(master=self,material=material,measure=measure,cnt=row[8],brand=force_text(row[3]), cost_price=row[7],sale_price=row[6]) total_amount += decimal.Decimal(row[6])*decimal.Decimal(row[8]) sql = 'update sale_offersheet set amount = %s where id=%s' params = [total_amount,self.id] generic.update(sql,params)