コード例 #1
0
    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
コード例 #2
0
    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
コード例 #3
0
ファイル: views.py プロジェクト: rcludwick/InvenTree
    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
コード例 #4
0
 def get_title(obj: Rate) -> str:
     """
     Get the currency title
     """
     currency = CURRENCIES.get(obj.currency)
     return _(getattr(currency, 'name', '-'))
コード例 #5
0
 def get_countries(obj: Rate) -> list:
     """
     Get the currency countries
     """
     currency = CURRENCIES.get(obj.currency)
     return getattr(currency, 'countries', '-')
コード例 #6
0
ファイル: serializers.py プロジェクト: webmalc/d8base-backend
 def get_title(rate: Rate) -> str:
     """Get the currency title."""
     currency = CURRENCIES.get(rate.currency)
     return _(getattr(currency, "name", "-").strip())
コード例 #7
0
ファイル: serializers.py プロジェクト: webmalc/d8base-backend
 def get_countries(rate: Rate) -> List[str]:
     """Get the currency countries."""
     currency = CURRENCIES.get(rate.currency)
     return getattr(currency, "countries", "-")