Esempio n. 1
0
    def update_order_status_from_magento(self, order_data=None):
        """Update order status from magento.

        :TODO: this only handles complete orders of magento. Should handle
        other states too?
        """
        Shipment = Pool().get('stock.shipment.out')

        if order_data is None:
            # XXX: Magento order_data is already there, so need not to
            # fetch again
            with magento.Order(
                self.channel.magento_url, self.channel.magento_api_user,
                self.channel.magento_api_key
            ) as order_api:
                order_data = order_api.info(self.reference)

        if order_data['status'] == 'complete':
            # Order is completed on magento, process shipments and
            # invoices.
            for shipment in self.shipments:
                if shipment.state == 'draft':
                    Shipment.wait([shipment])
                if shipment.state == 'waiting':
                    Shipment.assign([shipment])
                if shipment.state == 'assigned':
                    Shipment.pack([shipment])
                if shipment.state == 'packed':
                    Shipment.done([shipment])
Esempio n. 2
0
    def update_order_status_from_magento(self):
        """Update order status from magento.

        :TODO: this only handles complete orders of magento. Should handle
        other states too?
        """
        Shipment = Pool().get('stock.shipment.out')

        with magento.Order(self.channel.magento_url,
                           self.channel.magento_api_user,
                           self.channel.magento_api_key) as order_api:
            order_data = order_api.info(self.reference)

        if order_data['status'] == 'complete':
            # Order is completed on magento, process shipments and
            # invoices.
            for shipment in self.shipments:
                if shipment.state == 'draft':
                    Shipment.wait([shipment])
                if shipment.state == 'waiting':
                    Shipment.assign([shipment])
                if shipment.state == 'assigned':
                    Shipment.pack([shipment])
                if shipment.state == 'packed':
                    Shipment.done([shipment])
Esempio n. 3
0
    def process(cls, sales):
        super(Sale, cls).process(sales)
        Invoice = Pool().get('account.invoice')
        Shipment = Pool().get('stock.shipment.out')
        invoices = []
        for sale in sales:
            if sale.invoice_method != 'order' or \
                    sale.shipment_method != 'order':
                continue
            if sale.state != 'processing':
                continue
            if sale.shipments:
                if len(sale.shipments) > 1:
                    continue
                for ship in sale.shipments:
                    if ship.__class__.__name__ != 'stock.shipment.out':
                        continue
                    if ship.state != 'waiting':
                        continue
                    Shipment.assign([ship,])
                    Shipment.assign([ship,])
                    Shipment.pack([ship,])
                    Shipment.done([ship,])

            for inv in sale.invoices:
                if inv.state == 'draft':
                    inv.invoice_date = sale.sale_date
                    inv.save()
                    invoices.append(inv)

        if invoices:
            Invoice.post(invoices)
Esempio n. 4
0
    def update_order_status_from_amazon_mws(self, order_data=None):
        """Update order status from amazon mws

        :TODO: this only handles shipped orders of amazon mws. Should handle
        other states too?
        """
        Shipment = Pool().get('stock.shipment.out')

        if order_data is None:
            order_api = self.channel.get_amazon_order_api()
            order_data = order_api.get_order(
                [self.channel_identifier]
            ).parsed['Orders']['Order']

        if order_data['OrderStatus']['value'] == "Canceled":
            # TODO
            # If not done
            # - cancel shipment
            # - cancel invoice or credit invoice
            pass

        if order_data['OrderStatus']['value'] == "Shipped":
            # Order is completed on amazon, process shipments and
            # invoices.
            for shipment in self.shipments:
                if shipment.state == 'draft':
                    Shipment.wait([shipment])
                if shipment.state == 'waiting':
                    Shipment.assign([shipment])
                if shipment.state == 'assigned':
                    Shipment.pack([shipment])
                if shipment.state == 'packed':
                    Shipment.done([shipment])
Esempio n. 5
0
    def process_fba_order(self):
        """
        Process FBA Orders as they are imported as past orders
        and handle their shipments.
        """
        Sale = Pool().get('sale.sale')
        Shipment = Pool().get('stock.shipment.out')

        Sale.quote([self])
        Sale.confirm([self])
        Sale.process([self])

        for shipment in self.shipments:
            if shipment.state == 'draft':
                Shipment.wait([shipment])
            if shipment.state == 'waiting':
                Shipment.assign([shipment])
            if shipment.state == 'assigned':
                Shipment.pack([shipment])
            if shipment.state == 'packed':
                Shipment.done([shipment])
Esempio n. 6
0
    def do_print_(self, action):
        data = {}
        for state_name, state in self.states.iteritems():
            if isinstance(state, StateView):
                data[state_name] = getattr(self, state_name)._default_values
        Move = data['start']['moves']
        for each in Move:
            if each['message_confirm'] == True:
                if each['starts'] == '00':
                    move_apply = each['move_apply']
                    for i in move_apply:
                        Moves = Pool().get('stock.move')
                        move_id = i['move_id']
                        move_line = Moves.search([('id', '=', move_id)])
                        if move_line:
                            dict = {}
                            dict['quantity'] = i['proposal']
                            if i['outgoing_audit'] == '00' and float(
                                    i['stock_level']) < float(i['proposal']):
                                return self.raise_user_error(u'药品请领单数量大于当前库存数')
                            if i['outgoing_audit']:
                                dict['outgoing_audit'] = i['outgoing_audit']
                            else:
                                dict['outgoing_audit'] = '00'
                            Moves.write(move_line, dict)
                        else:
                            self.raise_user_error(u'该请领单已经修改,请重新进行处理')
                if each['starts'] == '01':  # 中心请退
                    move_return = each['move_return']
                    for i in move_return:
                        Moves = Pool().get('stock.move')
                        move_id = i['move_id']
                        ddd = Moves.search([('id', '=', move_id)])
                        dict = {}
                        dict['quantity'] = i['return_quantity']
                        Moves.write(ddd, dict)

                if each['starts'] == '02' or '03':  # 冻结/非限制
                    move_frozen = each['move_frozen']
                    for i in move_frozen:
                        Moves = Pool().get('stock.move')
                        move_id = i['move_id']
                        ddd = Moves.search([('id', '=', move_id)])
                        dict = {}
                        dict['quantity'] = i['proposal']
                        Moves.write(ddd, dict)

                if each['starts'] == '04':  # 内部移动
                    move_straight = each['move_straight']
                    internal = Pool().get('stock.shipment.internal')
                    Date = Pool().get('ir.date')
                    today = Date.today()
                    lv = {}
                    lv['starts'] = data['start']['starts']
                    lv['company'] = 1
                    lv['to_location'] = data['start']['moves'][0][
                        'to_location']  # 中转库存地transfers
                    lv['from_location'] = data['start']['moves'][0][
                        'from_location']
                    lv['place_of_service'] = data['start']['moves'][0][
                        'place_of_service']
                    lv['state'] = u'draft'
                    lv['planned_date'] = today
                    lv['number'] = data['start']['moves'][0]['move_number']
                    list_dict = []
                    for i in move_straight:
                        if i['storage'] == True:
                            Moves = Pool().get('stock.move')
                            move_id = i['move_id']
                            ddd = Moves.search([('id', '=', move_id)])
                            dict = {}
                            dict['quantity'] = i['proposal']
                            Moves.write(ddd, dict)
                        else:
                            Moves = Pool().get('stock.move')
                            move_id = i['move_id']
                            ddd = Moves.search([('id', '=', move_id)])
                            Moves.delete(ddd)
                            dict = {}
                            dict['origin'] = None  # each['origin']
                            product_name = i['product']
                            product = Pool().get('product.product')
                            product_id = product.search([('name', '=',
                                                          product_name)])
                            ProductId = product_id[0].id
                            dict['product'] = ProductId
                            dict['from_location'] = data['start']['moves'][0][
                                'from_location']
                            dict['to_location'] = data['start']['moves'][0][
                                'to_location']
                            dict['lot'] = i['lot']
                            dict['starts'] = data['start']['starts']
                            dict['uom'] = i['uom']
                            dict['real_number'] = i['proposal']  # 产品的请领数量
                            dict['quantity'] = i['proposal']
                            list_dict.append(dict)
                            lv['moves'] = [['create', list_dict]]
                    if 'moves' in lv.keys():
                        internal.create([lv])

                if each['starts'] == '05':  # 二级请退
                    move_return_two = each['move_return_two']
                    for i in move_return_two:
                        Moves = Pool().get('stock.move')
                        move_id = i['move_id']
                        ddd = Moves.search([('id', '=', move_id)])
                        dict = {}
                        dict['quantity'] = i['return_quantity']
                        Moves.write(ddd, dict)

                if each['starts'] == '06':  # 二级药库请领
                    move_look_two = each['move_look_two']
                    internal = Pool().get('stock.shipment.internal')
                    Date = Pool().get('ir.date')
                    today = Date.today()
                    lv = {}
                    lv['starts'] = data['start']['starts']
                    lv['company'] = 1
                    lv['to_location'] = data['start']['moves'][0][
                        'to_location']  # 中转库存地transfers
                    lv['from_location'] = data['start']['moves'][0][
                        'from_location']
                    lv['place_of_service'] = data['start']['moves'][0][
                        'place_of_service']
                    lv['state'] = u'draft'
                    lv['planned_date'] = today
                    lv['number'] = data['start']['moves'][0]['move_number']
                    if data['start']['starts'] == '06':
                        lv['straights'] = True
                    else:
                        pass
                    lv['drug_starts'] = data['start']['drug_starts']
                    list_dict = []
                    for i in move_look_two:
                        if i['storage'] == True:
                            Moves = Pool().get('stock.move')
                            move_id = i['move_id']
                            ddd = Moves.search([('id', '=', move_id)])
                            dict = {}
                            dict['quantity'] = i['proposal']
                            Moves.write(ddd, dict)
                        else:
                            Moves = Pool().get('stock.move')
                            move_id = i['move_id']
                            ddd = Moves.search([('id', '=', move_id)])
                            Moves.delete(ddd)
                            dict = {}
                            dict['origin'] = None  # each['origin']
                            product_name = i['product']
                            product = Pool().get('product.product')
                            product_id = product.search([('name', '=',
                                                          product_name)])
                            ProductId = product_id[0].id
                            dict['product'] = ProductId
                            dict['from_location'] = data['start']['moves'][0][
                                'from_location']
                            dict['to_location'] = data['start']['moves'][0][
                                'to_location']
                            dict['invoice_lines'] = ()  # each['invoice_lines']
                            dict['company'] = 1  # each['company']
                            dict['is_direct_sending'] = i[
                                'is_direct_sending']  # 是否直送
                            dict['lot'] = i['lot']
                            dict['starts'] = data['start']['starts']
                            dict['uom'] = i['company']
                            dict['real_number'] = i['proposal']  # 产品的请领数量
                            dict['quantity'] = i['proposal']
                            dict['a_charge'] = i['a_charge']
                            list_dict.append(dict)
                            lv['moves'] = [['create', list_dict]]
                    if 'moves' in lv.keys():
                        internal.create([lv])

        for move in data['start']['moves']:
            if move['message_confirm'] == True:
                move_number = move['move_number']
                shipment_id = move['shipment_id']
                internal = Pool().get('stock.shipment.internal')
                Internal = internal.search([
                    ('number', '=', move_number),
                    ('id', '=', shipment_id),
                ])
                internal.wait(Internal)
                internal.assign(Internal)
                internal.done(Internal)
            else:
                pass
Esempio n. 7
0
    def do_create_(self, action):
        Product = Pool().get('product.product')
        ProductQuantity = Pool().get('product_quantity')
        Purchase = Pool().get('purchase.purchase')
        Company = Pool().get('company.company')
        Date = Pool().get('ir.date')
        Move = Pool().get('stock.move')
        Lot = Pool().get('stock.lot')
        today = str(Date.today())
        Config = Pool().get('purchase.configuration')
        config = Config(1)
        company = Company.search([('id', '=', Transaction().context['company'])
                                  ])
        currency = company[0].currency
        Invoice = Pool().get('account.invoice')
        ShipmentIn = Pool().get('stock.shipment.in')
        PurchaseBills = Pool().get('purchase_bills')
        ShipmentInReturn = Pool().get('stock.shipment.in.return')
        data = {}
        for state_name, state in self.states.iteritems():
            if isinstance(state, StateView):
                data[state_name] = getattr(self, state_name)._default_values
        message = ''
        for each in data['start']['stock_return_lines']:
            if each['ensure'] == True and data['start'][
                    'order_category'] == 'return':
                shipmentinreturn = ShipmentInReturn.search([
                    ('id', '=', each['return_id']), ('state', '!=', 'done')
                ])
                if not shipmentinreturn:
                    message = u'该单号已被处理,请退出后重新查询。'
                    continue
                whether_move = Move.assign_try(
                    [Move(shipmentinreturn[0].moves[0].id)],
                    grouping=('product', 'lot'))
                if not whether_move:
                    message += shipmentinreturn[0].moves[
                        0].product.code + shipmentinreturn[0].moves[
                            0].product.name + u'-批次:' + Lot(
                                shipmentinreturn[0].moves[0].lot
                            ).number + u'实际数量有变,请删除该行项目后重新输入\n'
                    continue
                ShipmentInReturn.assign(shipmentinreturn)
                ShipmentInReturn.done(shipmentinreturn)
            if each['ensure'] == True and data['start'][
                    'order_category'] == 'purchase':
                purchase_bills = PurchaseBills.search([('id', '=',
                                                        each['purchase_id'])])
                purchase = Purchase.search([
                    ('number', '=', purchase_bills[0].order_code)
                ])  # ,('state', '!=', 'processing')
                if not purchase:
                    message = u'该单号已被处理,请退出后重新查询。'
                    continue
                PurchaseBills.write(purchase_bills, {'state': 'done'})
                Purchase.quote(purchase)
                Purchase.confirm(purchase)
                Purchase.process(purchase)
                moves = Move.search([
                    ('product', '=', purchase_bills[0].product.id),
                    ('purchase', '=', purchase_bills[0].order_code),
                    ('state', '=', 'draft')
                ])
                Move.write(
                    moves, {
                        'outgoing_audit': '02',
                        'lot': purchase_bills[0].lot.id,
                        'quantity': purchase_bills[0].shipment_quantity,
                        'move_type': '101'
                    })
                lv = {}
                if moves != []:
                    lv['incoming_moves'] = [['add', [moves[0].id]]]
                lv['reference'] = ''
                lv['planned_date'] = today
                lv['return_shipment'] = purchase_bills[0].return_shipment
                lv['company'] = Transaction().context.get('company')
                lv['effective_date'] = None
                lv['cause'] = '00'
                lv['warehouse'] = config.warehouse.id
                lv['supplier'] = purchase_bills[0].party.id
                lv['inventory_moves'] = []
                shipments = ShipmentIn.create([lv])
                shipment = ShipmentIn.search([('id', '=', shipments[0].id)])
                ShipmentIn.receive(shipment)
                ShipmentIn.done(shipment)
                invoices = Invoice.search([
                    ('state', '=', 'draft'),
                    ('id', 'in', [
                        ids.id
                        for ids in [i
                                    for i in [k.invoices for k in purchase]][0]
                    ])
                ])
                Invoice.write(
                    invoices, {
                        'invoice_date': purchase_bills[0].purchase_create_time,
                        'reference': purchase_bills[0].invoice_code,
                        'description':
                        purchase_bills[0].return_shipment.number,
                        'amount': purchase_bills[0].amount_of_real_pay
                    })
                Invoice.validate_invoice(invoices)
                Invoice.validate_invoice(invoices)

                product_quantities = ProductQuantity.search(
                    [('product', '=', purchase_bills[0].product.id)],
                    order=[["sequence", "ASC"]])
                move = {
                    u'comment': u'',
                    u'outgoing_audit': u'00',
                    u'product': purchase_bills[0].product.id,
                    u'from_location': config.warehouse.storage_location.id,
                    u'invoice_lines': [],
                    u'starts': u'05',
                    u'move_type': '000',
                    u'company': Transaction().context.get('company'),
                    u'unit_price': purchase_bills[0].product.cost_price,
                    u'currency': currency.id,
                    u'reason': '00',
                    u'lot': purchase_bills[0].lot.id,
                    u'planned_date': today,
                    u'uom': purchase_bills[0].product.default_uom.id,
                    u'origin': None,  # u'sale.line,-1',
                }
                move_quantity = purchase_bills[0].shipment_quantity
                for product_quantity in product_quantities:
                    with Transaction().set_context(
                            stock_date_end=Date.today()):  # 查看具体库下面的批次对应的数量
                        warehouse_quant = Product.products_by_location(
                            [product_quantity.location.id],
                            [purchase_bills[0].product.id],
                            with_childs=True)
                        move['to_location'] = product_quantity.location.id
                        warehouse_quantity = warehouse_quant[(
                            product_quantity.location.id,
                            purchase_bills[0].product.id)]
                        if product_quantity.quantity - warehouse_quantity >= move_quantity:
                            move['quantity'] = move_quantity
                            if move['quantity'] < 0:
                                self.raise_user_error(u'当前库存已超过最大库存!')
                            moves = Move.create([move])
                            Move.do(moves)
                            break
                        else:
                            move[
                                'quantity'] = product_quantity.quantity - warehouse_quantity
                            if move['quantity'] < 0:
                                self.raise_user_error(u'当前库存已超过最大库存!')
                            move_quantity = move_quantity + warehouse_quantity - product_quantity.quantity
                            moves = Move.create([move])
                            Move.do(moves)
        if message:
            self.raise_user_error(message)
        return action, {}
Esempio n. 8
0
    def do_create_(self, action):
        Date = Pool().get('ir.date')
        today = Date.today()
        UserId = Pool().get('hrp_internal_delivery.test_straight')
        to_location_id = UserId.get_user_id()

        Config = Pool().get('purchase.configuration')
        config = Config(1)  # 库存地配置
        internal = Pool().get('stock.shipment.internal')
        new_return = Pool().get('hrp_new_product.new_return')
        Product = Pool().get('product.product')
        data = {}
        for state_name, state in self.states.iteritems():
            if isinstance(state, StateView):
                data[state_name] = getattr(self, state_name)._default_values
        lv = {}
        Move = data['start']['moves']
        MOVE = Pool().get('hrp_new_product.new_return')
        UserId = Pool().get('hrp_internal_delivery.test_straight')
        from_location_id = UserId.get_user_id()
        list_now = []
        scrap = [
            ('examine', '=', '02'),
            ('from_location', '=', from_location_id),
        ]
        if data['start']['drug_type'] == '06':
            pass
        else:
            scrap.append(('drug_type', '=', data['start']['drug_type']))
        mmm = MOVE.search(scrap)
        for i in mmm:
            dict = {}
            dict['product'] = i.product.id
            dict['return_quantity'] = i.can_return_quantity
            list_now.append(dict)
        now_data = sorted(list_now,
                          key=lambda x: (x['product'], x['return_quantity']),
                          reverse=False)
        UserId = Pool().get('hrp_internal_delivery.test_straight')
        list_compare = []
        for each in Move:
            dict = {}
            dict['product'] = each['product']
            dict['return_quantity'] = each['return_quantity']
            list_compare.append(dict)
        # list_compare = UserId.get_default_moves_now()
        before_data = sorted(list_compare,
                             key=lambda x:
                             (x['product'], x['return_quantity']),
                             reverse=False)

        product_id = []
        for each in before_data:
            product_id.append(each['product'])
        a = {}
        for p_id in product_id:
            if product_id.count(p_id) > 1:
                a[p_id] = product_id.count(p_id)
        key_value = a.keys()
        productid = []
        now_list = []
        for each_ in before_data:
            if each_['product'] in key_value:
                dict = {}
                dict[each_['product']] = each_['return_quantity']
                productid.append(dict)
                now_list.append(each_)
        expected = [l for l in before_data if l not in now_list]
        for pro in key_value:
            number = 0
            dict_ = {}
            for i in productid:
                try:
                    number += i[pro]
                except:
                    pass
            dict_['product'] = pro
            dict_['return_quantity'] = number
            expected.append(dict_)
        expected_data = sorted(expected,
                               key=lambda x:
                               (x['product'], x['return_quantity']),
                               reverse=False)
        if expected_data == now_data:
            list = []
            for each in Move:
                get_apply_number = UserId.get_apply_number(to_location_id)
                lv['number'] = get_apply_number
                lv['starts'] = '01'
                lv['to_location'] = config.transfers.id  # 中转库存地
                lv['from_location'] = each['to_location']
                lv['company'] = 1  # data['start']['company']
                lv['state'] = data['start']['state']
                lv['place_of_service'] = config.return_of.id  # 到达库存地(中心药库冻结区)
                lv['drug_starts'] = data['start']['drug_type']
                dict = {}
                if each['reason'] == '00':
                    pass
                else:
                    dict['origin'] = None
                    dict['starts'] = data['start']['actives']
                    dict['product'] = each['product']
                    dict['planned_date'] = data['start']['planned_date']
                    dict['from_location'] = each['to_location']
                    dict['to_location'] = config.transfers.id  # 中转库存地
                    dict['is_direct_sending'] = each['is_direct_sending']
                    dict['company'] = 1
                    dict['reason'] = each['reason']
                    dict['comment'] = each['comment']
                    dict['invoice_lines'] = ()
                    dict['unit_price'] = None  # each['unit_price']
                    dict['lot'] = each['lot']
                    dict['uom'] = each['uom']
                    dict['quantity'] = each['return_quantity']
                    dict['real_number'] = each['return_quantity']
                    with Transaction().set_context(
                            stock_date_end=today,
                            stock_assign=True):  # 查看具体库下面的批次对应的数量
                        warehouse_quant = Product.products_by_location(
                            [each['to_location']], [each['product']],
                            [each['lot']],
                            grouping=('product', 'lot'))
                        for key, value in warehouse_quant.items():
                            if value > each['return_quantity']:
                                pass
                            else:
                                return self.raise_user_error(
                                    u'%s,数量不满足,请联系采购确认可退数量',
                                    each['product_name'])
                    cost_prices = Product.search([('id', '=', each['product'])
                                                  ])[0].cost_price
                    list_prices = Product.search([('id', '=', each['product'])
                                                  ])[0].list_price

                    list_ = decimal.Decimal(
                        str(
                            float(list_prices * decimal.Decimal(
                                str(each['return_quantity'])))))  # 批发总价
                    cost_ = decimal.Decimal(
                        str(
                            float(cost_prices * decimal.Decimal(
                                str(each['return_quantity'])))))  # 零售总价

                    list_price = decimal.Decimal(-list_).quantize(
                        decimal.Decimal('0.00'))
                    cost_price = decimal.Decimal(-cost_).quantize(
                        decimal.Decimal('0.00'))
                    dict['list_price'] = list_price
                    dict['cost_price'] = cost_price
                    list.append(dict)
                    lv['moves'] = [['create', list]]
                    NewReturn = new_return.search([
                        ('product', '=', each['product']),
                        ('from_location', '=', each['from_location']),
                    ])
                    if NewReturn:
                        write_dict = {}
                        write_dict['examine'] = '01'
                        write_dict['can_return_quantity'] = None
                        new_return.write(NewReturn, write_dict)
        else:
            return self.raise_user_error(u'数据有所更新,请您退出该界面重新进行操作')
        internal.create([lv])

        Internal = internal.search([
            ('from_location', '=', data['start']['moves'][0]['to_location'])
        ])
        internal.wait(Internal)
        internal.assign(Internal)
        internal.done(Internal)
        return action, {}
Esempio n. 9
0
    def do_create_(self, action):
        Config = Pool().get('purchase.configuration')
        config = Config(1)  # 库存地配置
        ShipmentInternal = Pool().get('stock.shipment.internal')
        internal = Pool().get('stock.shipment.internal')
        MoveNumber = Pool().get('stock.move')
        new_return = Pool().get('hrp_new_product.new_return')
        Product = Pool().get('product.product')
        UOM = Pool().get('product.uom')
        data = {}
        for state_name, state in self.states.iteritems():
            if isinstance(state, StateView):
                data[state_name] = getattr(self, state_name)._default_values
        lv = {}
        lv['company'] = 1
        lv['starts'] = data['start']['type']
        lv['to_location'] = data['start']['to_location']
        lv['from_location'] = data['start']['from_location']
        lv['state'] = u'draft'
        if data['start']['type'] == '02':
            states = '02'
        else:
            states = '03'
        Move = data['start']['moves']
        list = []
        for each in Move:
            if each['is_collar'] == True:
                dict = {}
                dict['origin'] = None  # each['origin']
                dict['to_location'] = data['start']['to_location']
                dict['product'] = each['product']
                dict['from_location'] = data['start']['from_location']
                dict['invoice_lines'] = ()  # each['invoice_lines']
                dict['company'] = 1  # each['company']
                dict['unit_price'] = None  # each['unit_price']产品的价格
                dict['lot'] = each['lot']  # 产品批次
                dict['uom'] = each['uom']  # 产品单位
                dict['starts'] = states
                dict['real_number'] = each['proposal']  # 产品的请领数量
                dict['quantity'] = each['proposal']

                ProductUom = Product.search([('id', '=', each['product'])])
                uom = ProductUom[0].template.default_uom
                cost_p = Product.search([('id', '=', each['product'])
                                         ])[0].cost_price
                list_p = Product.search([('id', '=', each['product'])
                                         ])[0].list_price
                eachuom = UOM.search([('id', '=', each['uom'])])[0]

                cost_prices = Uom.compute_price(uom, cost_p, eachuom)
                list_prices = Uom.compute_price(uom, list_p, eachuom)

                done_list = decimal.Decimal(
                    str(
                        float(list_prices *
                              decimal.Decimal(str(each['proposal'])))))  # 批发总价
                list_price = decimal.Decimal(done_list).quantize(
                    decimal.Decimal('0.00'))

                done_cost = decimal.Decimal(
                    str(
                        float(cost_prices *
                              decimal.Decimal(str(each['proposal'])))))  # 零售总价
                cost_price = decimal.Decimal(done_cost).quantize(
                    decimal.Decimal('0.00'))

                dict['list_price'] = list_price
                dict['cost_price'] = cost_price

                list.append(dict)
                lv['moves'] = [['create', list]]
                lv['planned_date'] = data['start']['planned_date']
                hrp_new_return = new_return.search([
                    ('product', '=', each['product']),
                    ('to_location', '=', data['start']['to_location']),
                    ('from_location', '=', data['start']['from_location']),
                ])
                if hrp_new_return:
                    return_dicts = {}
                    number = hrp_new_return[0].return_quantity
                    if number == None:
                        number = 0
                    Numbe = number + each['proposal']
                    return_dicts['return_quantity'] = Numbe
                    new_return.write(hrp_new_return, return_dicts)
                else:
                    if data['start']['type'] == '03':
                        pass
                    else:
                        return_dict = {}
                        return_dict['return_quantity'] = each[
                            'proposal']  # 产品的冻结/非限制数量
                        return_dict['to_location'] = data['start'][
                            'to_location']
                        return_dict['code'] = each['code']
                        return_dict['product'] = each['product']
                        return_dict['drug_specifications'] = each[
                            'drug_specifications']
                        return_dict['from_location'] = data['start'][
                            'from_location']
                        if data['start'][
                                'from_location'] == config.warehouse.storage_location.id:
                            return_dict['examine'] = '00'
                        else:
                            return_dict['examine'] = '01'
                        return_dict['drug_type'] = each['drug_type']
                        return_dict['retrieve_the_code'] = each[
                            'retrieve_the_code']
                        return_dict['lot'] = each['lot']  # 产品批次
                        # return_dict['list_price'] = done_list
                        # return_dict['cost_price'] = done_cost
                        ProductUom = Product.search([('id', '=',
                                                      each['product'])])
                        uom = ProductUom[0].template.default_uom.id
                        return_dict['uom'] = uom
                        new_return.create([return_dict])  # 创建到退药的表

        internal.create([lv])
        Internal = internal.search([
            ('to_location', '=', data['start']['to_location']),
            ('from_location', '=', data['start']['from_location']),
            ('planned_date', '=', data['start']['planned_date']),
            ('starts', '=', data['start']['type']),
        ])
        moves1 = Internal[0].moves
        move_id = []
        for i in moves1:
            move_id.append(i.id)
        move_ = MoveNumber.search([('id', 'in', move_id)])
        move_number = MoveNumber.assign_try(move_, grouping=('product', 'lot'))
        ShipmentInternal.wait(Internal)
        ShipmentInternal.assign(Internal)
        ShipmentInternal.done(Internal)
        if move_number == True:
            ShipmentInternal.wait(Internal)
            ShipmentInternal.assign(Internal)
            ShipmentInternal.done(Internal)
        else:
            product_name = move_[0].product.name
            product_lot = move_[0].lot.number
            return self.raise_user_error(product_name + u',批次:' + product_lot +
                                         u'实际数量有变 请删除该行项目后 重新输入')
        return action, {}