将move_lines传递给stock.picking从另一个模型--Odoo v8

时间:2017-11-11 04:14:12

标签: python python-2.7 odoo-8 odoo

我有这个方法:

class Game {
    private:
        Lvl *_levels[10];
    public:
        Game(Lvl* levels[10]){
            for(int i=0; i<10; i++) {
                _levels[i] = levels[i];
                cout << endl << "i : " << levels[i]->get_stage();
            }
        }
};

我正在尝试从其他模型创建Game game(lvls);

但是,使用这种方法,@api.multi def create_printy(self): copy_record = self.env['stock.picking'] for record in self: order_lines = [] for rec in record.order_lines: order_lines.append( (0,0, { 'product_id': rec.isbn.id, 'product_qty': rec.qty, } )) sp_types = self.env['stock.picking.type'].search([ ('code', '=', 'outgoing') ]) if len(sp_types) > 0: copy_record.create({ 'origin': record.name, 'picking_type_id': sp_types[0].id, 'move_lines': order_lines, 'move_type': 'direct', 'priority': '1', 'company_id': record.company_id.id, }) stock.pickingmove_lines有关,我遇到了问题。

现在,它引发了我的注意:

stock.picking

我知道我的stock.move字段中没有 Integrity Error The operation cannot be completed, probably due to the following: - deletion: you may be trying to delete a record while other records still reference it - creation/update: a mandatory field is not correctly set [object with reference: Product Unit of Measure - product.uom] 个必填字段。

所以,我的问题是,我如何通过我的模型中所需的stock.moveorder_lines

在我的示例中是否有与product.uom类似的方式。对于date_expected字段?

1 个答案:

答案 0 :(得分:2)

您可以看一下当您不在界面中填充这些字段时会发生什么(并查看默认情况下获得的内容)。例如,在stock.move Odoo从product_uom字段(通过product_id方法)获取onchange。并且date_expected默认填写当前日期。所以:

@api.multi
def create_printy(self):
    copy_record = self.env['stock.picking'] 
    for record in self:
        order_lines = []
        for rec in record.order_lines:
            order_lines.append(
            (0,0,
            {
                'product_id': rec.isbn.id,
                'product_uom': rec.isbn.uom_id.id,
                'date_expected': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
                'product_qty': rec.qty,
                }
            ))
        sp_types = self.env['stock.picking.type'].search([
        ('code', '=', 'outgoing')
        ])
        if len(sp_types) > 0:
            copy_record.create({
                'origin': record.name,
                'picking_type_id': sp_types[0].id,
                'move_lines': order_lines, 
                'move_type': 'direct',
                'priority': '1',
                'company_id': record.company_id.id,
            })

对于date_expected,您必须在 .py 文件中导出(在课程外)以下内容:

import time
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT