def get_initial(self): """ Provide initial data for new SupplierPart: - If 'supplier_id' provided, pre-fill supplier field - If 'part_id' provided, pre-fill part field """ initials = super(SupplierPartCreate, self).get_initial().copy() manufacturer_id = self.get_param('manufacturer') supplier_id = self.get_param('supplier') part_id = self.get_param('part') manufacturer_part_id = self.get_param('manufacturer_part') supplier = None if supplier_id: try: supplier = Company.objects.get(pk=supplier_id) initials['supplier'] = supplier except (ValueError, Company.DoesNotExist): supplier = None if manufacturer_id: try: initials['manufacturer'] = Company.objects.get(pk=manufacturer_id) except (ValueError, Company.DoesNotExist): pass if manufacturer_part_id: try: # Get ManufacturerPart instance information manufacturer_part_obj = ManufacturerPart.objects.get(pk=manufacturer_part_id) initials['part'] = Part.objects.get(pk=manufacturer_part_obj.part.id) initials['manufacturer'] = manufacturer_part_obj.manufacturer.id initials['MPN'] = manufacturer_part_obj.MPN except (ValueError, ManufacturerPart.DoesNotExist, Part.DoesNotExist, Company.DoesNotExist): pass if part_id: try: initials['part'] = Part.objects.get(pk=part_id) except (ValueError, Part.DoesNotExist): pass # Initial value for single pricing if supplier: currency_code = supplier.currency_code else: currency_code = common.settings.currency_code_default() currency = CURRENCIES.get(currency_code, None) if currency_code: initials['single_pricing'] = ('', currency) return initials
def get_initial(self): initials = super(AjaxCreateView, self).get_initial() supplier_part = self.get_part() initials['part'] = self.get_part() if supplier_part is not None: currency_code = supplier_part.supplier.currency_code else: currency_code = common.settings.currency_code_default() # Extract the currency object associated with the code currency = CURRENCIES.get(currency_code, None) if currency: initials['price'] = [1.0, currency] return initials
def get_initial(self): """ Provide initial data to create a new StockItem object """ # Is the client attempting to copy an existing stock item? item_to_copy = self.request.GET.get('copy', None) if item_to_copy: try: original = StockItem.objects.get(pk=item_to_copy) initials = model_to_dict(original) self.ajax_form_title = _("Duplicate Stock Item") except StockItem.DoesNotExist: initials = super(StockItemCreate, self).get_initial().copy() else: initials = super(StockItemCreate, self).get_initial().copy() part = self.get_part() loc_id = self.request.GET.get('location', None) sup_part_id = self.request.GET.get('supplier_part', None) location = None supplier_part = None if part is not None: initials['part'] = part initials['location'] = part.get_default_location() initials['supplier_part'] = part.default_supplier # If the part has a defined expiry period, extrapolate! if part.default_expiry > 0: expiry_date = datetime.now().date() + timedelta( days=part.default_expiry) initials['expiry_date'] = expiry_date currency_code = common.settings.currency_code_default() # SupplierPart field has been specified # It must match the Part, if that has been supplied if sup_part_id: try: supplier_part = SupplierPart.objects.get(pk=sup_part_id) if part is None or supplier_part.part == part: initials['supplier_part'] = supplier_part currency_code = supplier_part.supplier.currency_code except (ValueError, SupplierPart.DoesNotExist): pass # Location has been specified if loc_id: try: location = StockLocation.objects.get(pk=loc_id) initials['location'] = location except (ValueError, StockLocation.DoesNotExist): pass currency = CURRENCIES.get(currency_code, None) if currency: initials['purchase_price'] = (None, currency) return initials
def get_title(obj: Rate) -> str: """ Get the currency title """ currency = CURRENCIES.get(obj.currency) return _(getattr(currency, 'name', '-'))
def get_countries(obj: Rate) -> list: """ Get the currency countries """ currency = CURRENCIES.get(obj.currency) return getattr(currency, 'countries', '-')
def get_title(rate: Rate) -> str: """Get the currency title.""" currency = CURRENCIES.get(rate.currency) return _(getattr(currency, "name", "-").strip())
def get_countries(rate: Rate) -> List[str]: """Get the currency countries.""" currency = CURRENCIES.get(rate.currency) return getattr(currency, "countries", "-")