def source_line_to_order_lines(self, order, source_line): """ Convert a source line into one or more order lines. Normally each source line will yield just one order line, but package products will yield a parent line and its child lines. :type order: shoop.core.models.Order :param order: The order :type source_line: shoop.core.order_creator.SourceLine :param source_line: The SourceLine :rtype: Iterable[OrderLine] """ order_line = OrderLine(order=order) product = source_line.product quantity = Decimal(source_line.quantity) if product: order_line.product = product if product.sales_unit: quantized_quantity = bankers_round(quantity, product.sales_unit.decimals) if quantized_quantity != quantity: raise ValueError("Sales unit decimal conversion causes precision loss!") else: order_line.product = None def text(value): return force_text(value) if value is not None else "" order_line.quantity = quantity order_line.supplier = source_line.supplier order_line.sku = text(source_line.sku) order_line.text = (text(source_line.text))[:192] if source_line.base_unit_price: order_line.base_unit_price = source_line.base_unit_price if source_line.discount_amount: order_line.discount_amount = source_line.discount_amount order_line.type = (source_line.type if source_line.type is not None else OrderLineType.OTHER) order_line.accounting_identifier = text(source_line.accounting_identifier) order_line.require_verification = bool(source_line.require_verification) order_line.verified = (not order_line.require_verification) order_line.source_line = source_line order_line.parent_source_line = source_line.parent_line self._check_orderability(order_line) yield order_line for child_order_line in self.create_package_children(order_line): yield child_order_line
def get_chart(self): aggregate_data = group_by_period( Order.objects.valid().since(days=365), "order_date", "month", sum=Sum("taxful_total_price") ) locale = get_current_babel_locale() bar_chart = BarChart(title=_("Sales per Month (last year)"), labels=[ format_date(k, format=get_year_and_month_format(locale), locale=locale) for k in aggregate_data ]) bar_chart.add_data( _("Sales (%(currency)s)") % {"currency": settings.SHOOP_HOME_CURRENCY}, [bankers_round(v["sum"], settings.SHOOP_ORDER_TOTAL_DECIMALS) for v in aggregate_data.values()] ) return bar_chart
def source_line_to_order_lines(self, order, source_line): """ Convert a SourceLine into one or more OrderLines (yield them) :param order: The order :param source_line: The SourceLine """ order_line = OrderLine(order=order) product = source_line.product quantity = Decimal(source_line.quantity) if product: order_line.product = product if product.sales_unit: quantized_quantity = bankers_round(quantity, product.sales_unit.decimals) if quantized_quantity != quantity: raise ValueError( "Sales unit decimal conversion causes precision loss!") else: order_line.product = None def text(value): return force_text(value) if value is not None else "" order_line.quantity = quantity order_line.supplier = source_line.supplier order_line.sku = text(source_line.sku) order_line.text = (text(source_line.text))[:192] if source_line.unit_price: order_line.unit_price = source_line.unit_price if source_line.total_discount: order_line.total_discount = source_line.total_discount order_line.type = (source_line.type if source_line.type is not None else OrderLineType.OTHER) order_line.accounting_identifier = text( source_line.accounting_identifier) order_line.require_verification = bool( source_line.require_verification) order_line.verified = False order_line.source_line = source_line self._check_orderability(order_line) yield order_line for child_order_line in self.create_package_children(order_line): yield child_order_line
def source_line_to_order_lines(self, order, source_line): """ Convert a SourceLine into one or more OrderLines (yield them) :param order: The order :param source_line: The SourceLine """ order_line = OrderLine(order=order) product = source_line.product quantity = Decimal(source_line.quantity) if product: order_line.product = product if product.sales_unit: quantized_quantity = bankers_round(quantity, product.sales_unit.decimals) if quantized_quantity != quantity: raise ValueError("Sales unit decimal conversion causes precision loss!") else: order_line.product = None def text(value): return force_text(value) if value is not None else "" order_line.quantity = quantity order_line.supplier = source_line.supplier order_line.sku = text(source_line.sku) order_line.text = (text(source_line.text))[:192] if source_line.base_unit_price: order_line.base_unit_price = source_line.base_unit_price if source_line.discount_amount: order_line.discount_amount = source_line.discount_amount order_line.type = (source_line.type if source_line.type is not None else OrderLineType.OTHER) order_line.accounting_identifier = text(source_line.accounting_identifier) order_line.require_verification = bool(source_line.require_verification) order_line.verified = False order_line.source_line = source_line self._check_orderability(order_line) yield order_line for child_order_line in self.create_package_children(order_line): yield child_order_line
def get_chart(self): orders = get_orders_by_currency(self.currency) aggregate_data = group_by_period( orders.valid().since(days=365), "order_date", "month", sum=Sum("taxful_total_price_value") ) locale = get_current_babel_locale() bar_chart = BarChart(title=_("Sales per Month (last year)"), labels=[ format_date(k, format=get_year_and_month_format(locale), locale=locale) for k in aggregate_data ]) bar_chart.add_data( _("Sales (%(currency)s)") % {"currency": self.currency}, [ bankers_round(v["sum"], 2) # TODO: To be fixed in SHOOP-1912 for v in aggregate_data.values() ] ) return bar_chart
def get_chart(self): orders = get_orders_by_currency(self.currency) aggregate_data = group_by_period(orders.valid().since(days=365), "order_date", "month", sum=Sum("taxful_total_price_value")) locale = get_current_babel_locale() bar_chart = BarChart(title=_("Sales per Month (last year)"), labels=[ format_date( k, format=get_year_and_month_format(locale), locale=locale) for k in aggregate_data ]) bar_chart.add_data( _("Sales (%(currency)s)") % {"currency": self.currency}, [ bankers_round(v["sum"], 2) # TODO: To be fixed in SHOOP-1912 for v in aggregate_data.values() ]) return bar_chart
def _round_price(value): return bankers_round(value, settings.SHOOP_ORDER_TOTAL_DECIMALS)
def _round_price(value): return bankers_round(value, 2) # TODO: To be fixed in SHOOP-1912
def round(self, value): return bankers_round(parse_decimal_string(value), self.decimals)