analyse_view.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. from odoo import tools
  3. from odoo import models, fields, api
  4. import odoo.addons.decimal_precision as dp
  5. # 不能使用self.env[_name].search,应该是没有id字段的原因
  6. class AnalyseView(models.Model):
  7. _name = 'jc_demo.analyse_view'
  8. _description = u'Demo:分析视图'
  9. _auto = False
  10. sale_order_id = fields.Integer(string="销售订单ID")
  11. store_id = fields.Many2one('archives.store', string=u'仓库')
  12. date = fields.Date(string=u'日期')
  13. goods_id = fields.Many2one('archives.goods', string=u'物料',domain=lambda self: self.env['archives.organization'].get_organization_condition(
  14. 'active_goods'))
  15. main_unit_number = fields.Float(digits=dp.get_precision(), string=u'数量')
  16. money = fields.Float(digits=dp.get_precision(), string=u'金额')
  17. def init(self):
  18. view_sql = self._get_sqls()
  19. sql = """
  20. DROP VIEW IF EXISTS jc_demo_analyse_view;
  21. create view jc_demo_analyse_view as (
  22. {}
  23. )
  24. """.format(view_sql)
  25. cr = self._cr
  26. tools.drop_view_if_exists(cr, 'jc_demo_analyse_view')
  27. cr.execute(sql)
  28. def _get_sqls(self):
  29. sql = """
  30. select
  31. b.id as sale_order_id,
  32. b.store_id,
  33. b.out_store_date as date,
  34. d.goods_id,
  35. d.main_unit_number,
  36. d.money as money
  37. FROM jc_supply_chain_sale_order b
  38. LEFT JOIN jc_supply_chain_sale_order_detail d on b.id=d.sale_order_id
  39. where b.bill_state in ('1', '10', '20')
  40. """
  41. return sql