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.

108 lines
4.7KB

  1. from odoo import fields, models, api, tools
  2. class SellOrderDetail(models.Model):
  3. _name = 'sell.order.detail'
  4. _description = '销售明细表'
  5. _auto = False
  6. date = fields.Date('销售日期')
  7. order_name = fields.Char('销售单据号')
  8. type = fields.Char('业务类型')
  9. user_id = fields.Many2one('res.users', '销售员')
  10. partner_id = fields.Many2one('partner', '客户')
  11. goods_code = fields.Char('商品编码')
  12. goods_id = fields.Many2one('goods', '商品名称')
  13. attribute = fields.Char('属性')
  14. warehouse_id = fields.Many2one('warehouse', '仓库')
  15. qty = fields.Float('数量', digits='Quantity')
  16. uom = fields.Char('单位')
  17. price = fields.Float('单价', digits='Price')
  18. amount = fields.Float('销售收入', digits='Amount')
  19. tax_amount = fields.Float('税额', digits='Amount')
  20. subtotal = fields.Float('价税合计', digits='Amount')
  21. margin = fields.Float('毛利', digits='Amount')
  22. money_state = fields.Char('收款状态')
  23. note = fields.Char('备注')
  24. last_receipt_date = fields.Date(string='最后收款日期')
  25. def init(self):
  26. cr = self._cr
  27. tools.drop_view_if_exists(cr, 'sell_order_detail')
  28. cr.execute("""
  29. CREATE or REPLACE VIEW sell_order_detail AS (
  30. SELECT MIN(wml.id) AS id,
  31. wm.date AS date,
  32. wm.name AS order_name,
  33. (CASE WHEN wm.origin = 'sell.delivery.sell' THEN '销售'
  34. ELSE '退货' END) AS type,
  35. wm.user_id AS user_id,
  36. wm.partner_id AS partner_id,
  37. goods.code AS goods_code,
  38. goods.id AS goods_id,
  39. attr.name AS attribute,
  40. wh.id AS warehouse_id,
  41. SUM(CASE WHEN wm.origin = 'sell.delivery.sell' THEN wml.goods_qty
  42. ELSE - wml.goods_qty END) AS qty,
  43. uom.name AS uom,
  44. wml.price AS price,
  45. SUM(CASE WHEN wm.origin = 'sell.delivery.sell' THEN wml.amount
  46. ELSE - wml.amount END) AS amount,
  47. SUM(CASE WHEN wm.origin = 'sell.delivery.sell' THEN wml.tax_amount
  48. ELSE - wml.tax_amount END) AS tax_amount,
  49. SUM(CASE WHEN wm.origin = 'sell.delivery.sell' THEN wml.subtotal
  50. ELSE - wml.subtotal END) AS subtotal,
  51. (SUM(CASE WHEN wm.origin = 'sell.delivery.sell' THEN wml.amount
  52. ELSE - wml.amount END) - SUM(CASE WHEN wm.origin = 'sell.delivery.sell' THEN wml.goods_qty
  53. ELSE - wml.goods_qty END) * wml.cost_unit) AS margin,
  54. (CASE WHEN wm.origin = 'sell.delivery.sell' THEN sd.money_state
  55. ELSE sd.return_state END) AS money_state,
  56. wml.note AS note,
  57. mi.get_amount_date AS last_receipt_date
  58. FROM wh_move_line AS wml
  59. LEFT JOIN wh_move wm ON wml.move_id = wm.id
  60. LEFT JOIN partner ON wm.partner_id = partner.id
  61. LEFT JOIN goods ON wml.goods_id = goods.id
  62. LEFT JOIN attribute AS attr ON wml.attribute_id = attr.id
  63. LEFT JOIN warehouse AS wh ON wml.warehouse_id = wh.id
  64. OR wml.warehouse_dest_id = wh.id
  65. LEFT JOIN uom ON goods.uom_id = uom.id
  66. LEFT JOIN sell_delivery AS sd ON wm.id = sd.sell_move_id
  67. LEFT JOIN money_invoice AS mi ON mi.id = sd.invoice_id
  68. WHERE wml.state = 'done'
  69. AND wm.origin like 'sell.delivery%%'
  70. AND wh.type = 'stock'
  71. GROUP BY wm.date, wm.name, origin, wm.user_id, wm.partner_id,
  72. goods_code, goods.id, attribute, wh.id, uom,
  73. wml.price, wml.cost_unit, sd.money_state, sd.return_state, wml.note,
  74. mi.get_amount_date
  75. )
  76. """)
  77. def view_detail(self):
  78. '''查看明细按钮'''
  79. self.ensure_one()
  80. order = self.env['sell.delivery'].search(
  81. [('name', '=', self.order_name)])
  82. if order:
  83. if not order.is_return:
  84. view = self.env.ref('sell.sell_delivery_form')
  85. else:
  86. view = self.env.ref('sell.sell_return_form')
  87. return {
  88. 'name': '销售发货单',
  89. 'view_mode': 'form',
  90. 'view_id': False,
  91. 'views': [(view.id, 'form')],
  92. 'res_model': 'sell.delivery',
  93. 'type': 'ir.actions.act_window',
  94. 'res_id': order.id,
  95. }
上海开阖软件有限公司 沪ICP备12045867号-1