Ejemplo n.º 1
0
    def advice(product):
        lead_deliver_day = format_decimal(product.get_lead_deliver_day())

        if product.available_quantity < 0:
            return u"""<span class="i_a_warning i_a_number">库存错误</span>,
                      请立即<a href="/admin/inventorytransaction/new" target="_blank">修正该错误</a>"""
        if product.available_quantity == 0 and product.weekly_sold_qty != 0:
            return u'库存为<span class="i_a_warning i_a_number">0</span>,请立即补货, ' \
                   u'补货需要<span class="i_a_warning i_a_number">' \
                   + str(lead_deliver_day) + u'</span>天,' \
                   + u'补货期间损失利润:<span class="i_a_warning i_a_number">' \
                   + str(format_decimal(product.get_profit_lost_caused_by_inventory_short())) \
                   + u'</span>元,' \
                   + u'<a href="/admin/dpo/new/" target="_blank">点此补货</a>'
        elif product.weekly_sold_qty > 0:
            can_sell_day = format_decimal(product.available_quantity / (product.weekly_sold_qty/7))
            if can_sell_day > lead_deliver_day:
                return u'当前库存可供销售<span class="i_a_number">' + str(can_sell_day) + "</span>天"
            elif can_sell_day < lead_deliver_day and product.in_transit_quantity == 0:
                return u'当前库存在新货品到达前即会售完,可销售<span class="i_a_number">' \
                       + str(can_sell_day) + u'</span>天' \
                       + u', 补货需要<span class="i_a_number">' + str(lead_deliver_day) + '</span>天,' \
                       + u'补货期间损失利润额<span class="i_a_number i_a_warning">' \
                       + str(format_decimal(product.get_profit_lost_caused_by_inventory_short())) \
                       + u'</span>元,' \
                       + u'<a href="/admin/dpo/new/" target="_blank">点此补货</a>'
        else:
            return u'-'
Ejemplo n.º 2
0
    def advice(product):
        lead_deliver_day = format_decimal(product.get_lead_deliver_day())

        if product.available_quantity < 0:
            return u"""<span class="i_a_warning i_a_number">库存错误</span>,
                      请立即<a href="/admin/inventorytransaction/new" target="_blank">修正该错误</a>"""
        if product.available_quantity == 0 and product.weekly_sold_qty != 0:
            return u'库存为<span class="i_a_warning i_a_number">0</span>,请立即补货, ' \
                   u'补货需要<span class="i_a_warning i_a_number">' \
                   + str(lead_deliver_day) + u'</span>天,' \
                   + u'补货期间损失利润:<span class="i_a_warning i_a_number">' \
                   + str(format_decimal(product.get_profit_lost_caused_by_inventory_short())) \
                   + u'</span>元,' \
                   + u'<a href="/admin/dpo/new/" target="_blank">点此补货</a>'
        elif product.weekly_sold_qty > 0:
            can_sell_day = format_decimal(product.available_quantity /
                                          (product.weekly_sold_qty / 7))
            if can_sell_day > lead_deliver_day:
                return u'当前库存可供销售<span class="i_a_number">' + str(
                    can_sell_day) + "</span>天"
            elif can_sell_day < lead_deliver_day and product.in_transit_quantity == 0:
                return u'当前库存在新货品到达前即会售完,可销售<span class="i_a_number">' \
                       + str(can_sell_day) + u'</span>天' \
                       + u', 补货需要<span class="i_a_number">' + str(lead_deliver_day) + '</span>天,' \
                       + u'补货期间损失利润额<span class="i_a_number i_a_warning">' \
                       + str(format_decimal(product.get_profit_lost_caused_by_inventory_short())) \
                       + u'</span>元,' \
                       + u'<a href="/admin/dpo/new/" target="_blank">点此补货</a>'
        else:
            return u'-'
Ejemplo n.º 3
0
 def _get_result(self, select_statement):
     if isinstance(self.id, int):
         result = self.query.session.execute(select_statement).first()
         val = format_decimal(result[0]) if (result is not None and result[0] is not None) else Decimal("0.00")
     else:
         val = Decimal("0.00")
     return val
Ejemplo n.º 4
0
 def weekly_sold_qty(self):
     """
     SQL:
     SELECT p.id, p.name,
       -sum(itl.quantity),
       -sum(itl.quantity) / (greatest(date_part('days', max(it.date) - min(it.date)), 1)/7),
     FROM
       inventory_transaction_line itl,
       inventory_transaction it,
       enum_values ev,
       product p
     where
       itl.inventory_transaction_id = it.id
       AND itl.product_id = p.id
       AND ev.code = 'SALES_OUT'
       AND it.type_id = ev.id
     GROUP BY p.id, p.name;
     :return: quantity of sold out product averaged by week.
     """
     i_ts = self.inventory_transaction_lines
     tot_qty = 0
     max_date, min_date = None, None
     if len(i_ts) > 0:
         for l in i_ts:
             if l.type.code == const.SALES_OUT_INV_TRANS_TYPE_KEY:
                 if l.quantity is not None and l.price is not None:
                     tot_qty += abs(l.quantity)
                 if max_date is None or l.inventory_transaction.date > max_date:
                     max_date = l.inventory_transaction.date
                 if min_date is None or l.inventory_transaction.date < min_date:
                     min_date = l.inventory_transaction.date
     weeks = get_weeks_between(min_date, max_date)
     if weeks == 0:
         weeks = 1
     return format_decimal(tot_qty / weeks)
Ejemplo n.º 5
0
 def weekly_sold_qty(self):
     """
     SQL:
     SELECT p.id, p.name,
       -sum(itl.quantity),
       -sum(itl.quantity) / (greatest(date_part('days', max(it.date) - min(it.date)), 1)/7),
     FROM
       inventory_transaction_line itl,
       inventory_transaction it,
       enum_values ev,
       product p
     where
       itl.inventory_transaction_id = it.id
       AND itl.product_id = p.id
       AND ev.code = 'SALES_OUT'
       AND it.type_id = ev.id
     GROUP BY p.id, p.name;
     :return: quantity of sold out product averaged by week.
     """
     i_ts = self.inventory_transaction_lines
     tot_qty = 0
     max_date, min_date = None, None
     if len(i_ts) > 0:
         for l in i_ts:
             if l.type.code == const.SALES_OUT_INV_TRANS_TYPE_KEY:
                 if l.quantity is not None and l.price is not None:
                     tot_qty += abs(l.quantity)
                 if max_date is None or l.inventory_transaction.date > max_date:
                     max_date = l.inventory_transaction.date
                 if min_date is None or l.inventory_transaction.date < min_date:
                     min_date = l.inventory_transaction.date
     weeks = get_weeks_between(min_date, max_date)
     if weeks == 0:
         weeks = 1
     return format_decimal(tot_qty / weeks)
Ejemplo n.º 6
0
 def cal_inv_trans_average(self, transaction_type):
     i_ts = self.inventory_transaction_lines
     tot_amt = 0
     tot_qty = 0
     if len(i_ts) > 0:
         for l in i_ts:
             if l.type.code == transaction_type:
                 if l.quantity is not None and l.price is not None:
                     tot_qty += abs(l.quantity)
                     tot_amt += abs(l.quantity) * l.price
     if tot_amt != 0 and tot_qty != 0:
         return format_decimal(tot_amt / tot_qty)
     return 0
Ejemplo n.º 7
0
 def cal_inv_trans_average(self, transaction_type):
     i_ts = self.inventory_transaction_lines
     tot_amt = 0
     tot_qty = 0
     if len(i_ts) > 0:
         for l in i_ts:
             if l.type.code == transaction_type:
                 if l.quantity is not None and l.price is not None:
                     tot_qty += abs(l.quantity)
                     tot_amt += abs(l.quantity) * l.price
     if tot_amt != 0 and tot_qty != 0:
         return format_decimal(tot_amt / tot_qty)
     return 0
Ejemplo n.º 8
0
 def weekly_average_profit(self):
     if 0 == self.average_unit_profit:
         return 0
     return format_decimal(self.weekly_sold_qty * self.average_unit_profit)
Ejemplo n.º 9
0
 def weekly_average_profit(self):
     if 0 == self.average_unit_profit:
         return 0
     return format_decimal(self.weekly_sold_qty * self.average_unit_profit)