def to_objects(self, error_collector: ErrorCollector): if self.delivered == "Yes": return [] if self.eta is None: return [] if self.functionality.lower() in {"full", "critical care"}: item = Item.ventilators_full_service elif self.functionality.lower() == "limited": item = Item.ventilators_non_full_service else: error_collector.report_error( f"Unknown ventilator type: {self.functionality}") return [] purchase = models.Purchase( order_type=OrderType.Purchase, item=item, quantity=self.quantity, received_quantity=self.quantity_delivered, description=f"Ventilator {self.type} ({self.functionality})", raw_data=self.raw_data, ) deliveries = [] if self.eta is not None: deliveries.append( models.ScheduledDelivery(purchase=purchase, delivery_date=self.eta, quantity=self.quantity)) return [purchase, *deliveries]
def to_objects(self, error_collector: ErrorCollector): objs = [] for mapping in item_mappings: item = asset_name_to_item(mapping.sheet_column_name, error_collector) quantity = getattr(self, mapping.obj_column_name) purchase = models.Purchase( item=item, quantity=quantity, vendor="Aggregate Data (no vendor available)", raw_data=self.raw_data, order_type=OrderType.Make, ) delivery = models.ScheduledDelivery( purchase=purchase, delivery_date=self.delivery_date, quantity=quantity, ) objs.append(purchase) objs.append(delivery) return objs
def to_objects(self, error_collector: ErrorCollector): errors = self.sanity() if errors: error_collector.report_error( f"Refusing to generate a data model for: {self}. Errors: {errors}" ) return [] purchase = models.Purchase( item=self.item, quantity=self.quantity, vendor=self.vendor, raw_data=self.raw_data, order_type=OrderType.Make, ) dates = [] if self.delivery_date: dates.append(self.delivery_date) elif "weekly" in self.raw_date: import re date_str = re.sub(r"[a-zA-Z ]+", "", self.raw_date).strip() end_date = parse_date(date_str, error_collector) if end_date: dates = [] while end_date > datetime.today(): dates.append(end_date) end_date -= timedelta(weeks=1) delivery = [ models.ScheduledDelivery( purchase=purchase, delivery_date=date, quantity=self.quantity, ) for date in dates ] return [purchase, *delivery]
def to_objects(self, error_collector: ErrorCollector): if self.status != "Completed": return [] errors = self.sanity(error_collector) if errors: error_collector.report_error( f"Refusing to generate a data model for: {self}. Errors: {errors}" ) return [] purchase = models.Purchase( item=self.item, quantity=self.quantity, received_quantity=self.received_quantity, vendor=self.vendor, raw_data=self.raw_data, order_type=OrderType.Purchase, description=self.description, ) deliveries = [] for day in [1, 2]: total = 0 if getattr(self, f"delivery_day_{day}"): quantity = getattr(self, f"delivery_day_{day}_quantity") if quantity is None: quantity = self.quantity - total error_collector.report_warning( f"Assuming that a null quantity means a full delivery for {self}" ) deliveries.append( models.ScheduledDelivery( purchase=purchase, delivery_date=getattr(self, f"delivery_day_{day}"), quantity=quantity, )) return [purchase, *deliveries]