odoo web加载sql视图

1.web端代码



    
        
            stock_inout_detail_list_tree
            stock.inout.detail
            
                
                    
                    
                    
                    
                    
                    
                    
                    
                    
                
            
        

        
            出入库明细
            ir.actions.act_window
            stock.inout.detail
            form
            tree
            
                

Click to start a new Call for Bids process.

tree

odoo web加载sql视图_第1张图片

2.服务端代码:

# _*_ coding: utf-8 _*_
from odoo import api, fields, models, tools


class StockInoutDetial(models.Model):
    _name = "stock.inout.detail"
    _auto = False
    _order = 'create_date asc'

    move_id = fields.Many2one('stock.move', u'Stock Move', required=True)
    # location_id = fields.Many2one('stock.location', 'Location', required=True)
    product_id = fields.Many2one('product.product', '产品', required=True)
    quantity = fields.Float('数量')
    create_date = fields.Datetime('创建日期')
    serial_number = fields.Char('追踪号', required=True)
    origin = fields.Char(u'源单据', required=True)
    picking_type_id = fields.Many2one('stock.picking.type',
                                      string=u'拣货类型')
    lot_id = fields.Many2one('stock.production.lot', string='追踪号/批次号')
    product_uom_id = fields.Many2one(
        'product.uom', string='单位', related='product_id.uom_id',
        readonly=True)
    force_date = fields.Datetime(u'强制时间')

    @api.model_cr
    def init(self):
        tools.drop_view_if_exists(self._cr, 'stock_inout_detail')
        self._cr.execute("""
                CREATE VIEW stock_inout_detail AS (
                  SELECT sq.id as id,
                    spl.id AS lot_id,
                    sqmr.move_id AS move_id,
                    sm.product_id AS product_id,
                    sm.create_date AS create_date,
                    sm.origin AS origin,
                    sm.picking_type_id AS picking_type_id,
                    sm.force_date,
                    sq.ref AS serial_number,
                    sq.qty AS quantity
                    FROM stock_quant_move_rel sqmr
                    LEFT JOIN stock_move sm ON sm.id=sqmr.move_id
                    LEFT JOIN stock_quant sq ON sq.id=sqmr.quant_id
                    LEFT JOIN stock_production_lot spl ON spl.id=sq.lot_id WHERE origin is not null
                )""")
odoo web加载sql视图_第2张图片


你可能感兴趣的:(Odoo)