12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- # -*- coding: utf-8 -*-
- from odoo import tools
- from odoo import models, fields, api
- import odoo.addons.decimal_precision as dp
- # 不能使用self.env[_name].search,应该是没有id字段的原因
- class AnalyseView(models.Model):
- _name = 'jc_demo.analyse_view'
- _description = u'Demo:分析视图'
- _auto = False
- sale_order_id = fields.Integer(string="销售订单ID")
- store_id = fields.Many2one('archives.store', string=u'仓库')
- date = fields.Date(string=u'日期')
- goods_id = fields.Many2one('archives.goods', string=u'物料',domain=lambda self: self.env['archives.organization'].get_organization_condition(
- 'active_goods'))
- main_unit_number = fields.Float(digits=dp.get_precision(), string=u'数量')
- money = fields.Float(digits=dp.get_precision(), string=u'金额')
- def init(self):
- view_sql = self._get_sqls()
- sql = """
- DROP VIEW IF EXISTS jc_demo_analyse_view;
- create view jc_demo_analyse_view as (
- {}
- )
- """.format(view_sql)
- cr = self._cr
- tools.drop_view_if_exists(cr, 'jc_demo_analyse_view')
- cr.execute(sql)
- def _get_sqls(self):
- sql = """
- select
- b.id as sale_order_id,
- b.store_id,
- b.out_store_date as date,
- d.goods_id,
- d.main_unit_number,
- d.money as money
- FROM jc_supply_chain_sale_order b
- LEFT JOIN jc_supply_chain_sale_order_detail d on b.id=d.sale_order_id
- where b.bill_state in ('1', '10', '20')
- """
- return sql
|