GoodERP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 satır
2.7KB

  1. from odoo import tools
  2. from odoo import models, fields
  3. class ReportStockBalance(models.Model):
  4. _name = 'report.stock.balance'
  5. _description = '库存余额表'
  6. _auto = False
  7. goods = fields.Char('商品名')
  8. goods_id = fields.Many2one('goods', '商品')
  9. code = fields.Char('编码', related='goods_id.code')
  10. brand_id = fields.Many2one('core.value', '品牌')
  11. location = fields.Char('库位')
  12. uom = fields.Char('单位')
  13. uos = fields.Char('辅助单位')
  14. lot = fields.Char('批号')
  15. expiration_date = fields.Date('过保日')
  16. attribute_id = fields.Char('属性')
  17. warehouse = fields.Char('仓库')
  18. goods_qty = fields.Float('数量', digits='Quantity')
  19. goods_uos_qty = fields.Float(
  20. '辅助单位数量', digits='Quantity')
  21. cost = fields.Float('成本', digits='Price')
  22. def init(self):
  23. cr = self._cr
  24. tools.drop_view_if_exists(cr, 'report_stock_balance')
  25. cr.execute(
  26. """
  27. create or replace view report_stock_balance as (
  28. SELECT min(line.id) as id,
  29. goods.name as goods,
  30. goods.id as goods_id,
  31. goods.code as code,
  32. goods.brand as brand_id,
  33. loc.name as location,
  34. line.lot as lot,
  35. line.expiration_date as expiration_date,
  36. attribute.name as attribute_id,
  37. uom.name as uom,
  38. uos.name as uos,
  39. wh.name as warehouse,
  40. sum(line.qty_remaining) as goods_qty,
  41. sum(line.uos_qty_remaining) as goods_uos_qty,
  42. sum(line.qty_remaining * line.cost_unit) as cost
  43. FROM wh_move_line line
  44. LEFT JOIN warehouse wh ON line.warehouse_dest_id = wh.id
  45. LEFT JOIN goods goods ON line.goods_id = goods.id
  46. LEFT JOIN attribute attribute on attribute.id = line.attribute_id
  47. LEFT JOIN uom uom ON goods.uom_id = uom.id
  48. LEFT JOIN uom uos ON goods.uos_id = uos.id
  49. LEFT JOIN location loc ON loc.id = line.location_id
  50. WHERE wh.type = 'stock'
  51. AND wh.active = true
  52. AND line.state = 'done'
  53. AND line.qty_remaining != 0
  54. AND ( goods.no_stock is null or goods.no_stock = FALSE)
  55. GROUP BY wh.name, line.lot, line.expiration_date, attribute.name, goods.name, goods.id, goods.brand, loc.name, uom.name, uos.name
  56. ORDER BY goods.name, wh.name, goods_qty asc
  57. )
  58. """)
上海开阖软件有限公司 沪ICP备12045867号-1