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.

97 lines
4.0KB

  1. # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import fields, models, api, tools
  4. class BuyOrderDetail(models.Model):
  5. _name = 'buy.order.detail'
  6. _description = '采购入库明细表'
  7. _auto = False
  8. date = fields.Date('采购日期')
  9. order_name = fields.Char('采购单据号')
  10. type = fields.Char('业务类型')
  11. partner_id = fields.Many2one('partner', '供应商')
  12. goods_code = fields.Char('商品编码')
  13. goods_id = fields.Many2one('goods', '商品名称')
  14. attribute = fields.Char('属性')
  15. warehouse_dest_id = fields.Many2one('warehouse', '仓库')
  16. qty = fields.Float('数量', digits='Quantity')
  17. uom = fields.Char('单位')
  18. price = fields.Float('单价', digits='Price')
  19. amount = fields.Float(
  20. '采购金额', digits='Amount') # 商品的采购金额
  21. tax_amount = fields.Float('税额', digits='Amount')
  22. subtotal = fields.Float('价税合计', digits='Amount')
  23. note = fields.Char('备注')
  24. def init(self):
  25. cr = self._cr
  26. tools.drop_view_if_exists(cr, 'buy_order_detail')
  27. cr.execute("""
  28. CREATE or REPLACE VIEW buy_order_detail AS (
  29. SELECT MIN(wml.id) AS id,
  30. wm.date AS date,
  31. wm.name AS order_name,
  32. (CASE WHEN wm.origin = 'buy.receipt.buy' THEN '采购'
  33. ELSE '退货' END) AS type,
  34. wm.partner_id AS partner_id,
  35. goods.code AS goods_code,
  36. goods.id AS goods_id,
  37. attr.name AS attribute,
  38. wh.id AS warehouse_dest_id,
  39. SUM(CASE WHEN wm.origin = 'buy.receipt.buy' THEN wml.goods_qty
  40. ELSE - wml.goods_qty END) AS qty,
  41. uom.name AS uom,
  42. wml.price AS price,
  43. SUM(CASE WHEN wm.origin = 'buy.receipt.buy' THEN wml.amount
  44. ELSE - wml.amount END) AS amount,
  45. SUM(CASE WHEN wm.origin = 'buy.receipt.buy' THEN wml.tax_amount
  46. ELSE - wml.tax_amount END) AS tax_amount,
  47. SUM(CASE WHEN wm.origin = 'buy.receipt.buy' THEN wml.subtotal
  48. ELSE - wml.subtotal END) AS subtotal,
  49. wml.note AS note
  50. FROM wh_move_line AS wml
  51. LEFT JOIN wh_move wm ON wml.move_id = wm.id
  52. LEFT JOIN partner ON wm.partner_id = partner.id
  53. LEFT JOIN goods ON wml.goods_id = goods.id
  54. LEFT JOIN attribute AS attr ON wml.attribute_id = attr.id
  55. LEFT JOIN warehouse AS wh ON wml.warehouse_id = wh.id
  56. OR wml.warehouse_dest_id = wh.id
  57. LEFT JOIN uom ON goods.uom_id = uom.id
  58. LEFT JOIN buy_receipt AS br ON wm.id = br.buy_move_id
  59. WHERE wml.state = 'done'
  60. AND wm.origin like 'buy.receipt%%'
  61. AND wh.type = 'stock'
  62. GROUP BY wm.date, wm.name, origin, wm.partner_id,
  63. goods_code, goods.id, attribute, wh.id, uom,
  64. wml.price, wml.note
  65. )
  66. """)
  67. def view_detail(self):
  68. '''查看明细按钮'''
  69. self.ensure_one()
  70. order = self.env['buy.receipt'].search(
  71. [('name', '=', self.order_name)])
  72. if order:
  73. if not order.is_return:
  74. view = self.env.ref('buy.buy_receipt_form')
  75. else:
  76. view = self.env.ref('buy.buy_return_form')
  77. return {
  78. 'name': '采购入库单',
  79. '': 'form',
  80. 'view_mode': 'form',
  81. 'view_id': False,
  82. 'views': [(view.id, 'form')],
  83. 'res_model': 'buy.receipt',
  84. 'type': 'ir.actions.act_window',
  85. 'res_id': order.id,
  86. }
上海开阖软件有限公司 沪ICP备12045867号-1