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.

194 lines
8.5KB

  1. ##############################################################################
  2. #
  3. # OpenERP, Open Source Management Solution
  4. # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. from odoo import fields, models, api, tools
  21. from odoo.exceptions import UserError
  22. class CustomerStatementsReport(models.Model):
  23. _inherit = "customer.statements.report"
  24. _auto = False
  25. sale_amount = fields.Float(string='销售金额', readonly=True,
  26. digits='Amount')
  27. benefit_amount = fields.Float(string='优惠金额', readonly=True,
  28. digits='Amount')
  29. fee = fields.Float(string='客户承担费用', readonly=True,
  30. digits='Amount')
  31. move_id = fields.Many2one('wh.move', string='出入库单', readonly=True)
  32. def init(self):
  33. # union money_order(type = 'get'), money_invoice(type = 'income')
  34. cr = self._cr
  35. tools.drop_view_if_exists(cr, 'customer_statements_report')
  36. cr.execute("""
  37. CREATE or REPLACE VIEW customer_statements_report AS (
  38. SELECT ROW_NUMBER() OVER(ORDER BY partner_id, date, amount desc) AS id,
  39. partner_id,
  40. name,
  41. date,
  42. done_date,
  43. sale_amount,
  44. benefit_amount,
  45. fee,
  46. amount,
  47. pay_amount,
  48. discount_money,
  49. balance_amount,
  50. note,
  51. move_id
  52. FROM
  53. (
  54. SELECT m.partner_id,
  55. m.name,
  56. m.date,
  57. m.write_date AS done_date,
  58. 0 AS sale_amount,
  59. 0 AS benefit_amount,
  60. 0 AS fee,
  61. 0 AS amount,
  62. m.amount AS pay_amount,
  63. m.discount_amount as discount_money,
  64. 0 AS balance_amount,
  65. m.note,
  66. 0 AS move_id
  67. FROM money_order AS m
  68. WHERE m.type = 'get' AND m.state = 'done'
  69. UNION ALL
  70. SELECT mi.partner_id,
  71. mi.name,
  72. mi.date,
  73. mi.create_date AS done_date,
  74. sd.amount + sd.discount_amount AS sale_amount,
  75. sd.discount_amount AS benefit_amount,
  76. sd.partner_cost AS fee,
  77. mi.amount,
  78. 0 AS pay_amount,
  79. 0 as discount_money,
  80. 0 AS balance_amount,
  81. Null AS note,
  82. mi.move_id
  83. FROM money_invoice AS mi
  84. LEFT JOIN core_category AS c ON mi.category_id = c.id
  85. LEFT JOIN sell_delivery AS sd ON sd.sell_move_id = mi.move_id
  86. WHERE c.type = 'income' AND mi.state = 'done'
  87. ) AS ps)
  88. """)
  89. def find_source_order(self):
  90. # 查看原始单据,三种情况:收款单、销售退货单、销售发货单、核销单
  91. self.ensure_one()
  92. model_view = {
  93. 'money.order': {'name': '收款单',
  94. 'view': 'money.money_order_form'},
  95. 'sell.delivery': {'name': '销售发货单',
  96. 'view': 'sell.sell_delivery_form',
  97. 'name_return': '销售退货单',
  98. 'view_return': 'sell.sell_return_form'},
  99. 'reconcile.order': {'name': '核销单',
  100. 'view': 'money.reconcile_order_form'}
  101. }
  102. for model, view_dict in model_view.items():
  103. res = self.env[model].search([('name', '=', self.name)])
  104. name = model == 'sell.delivery' and res.is_return and \
  105. view_dict['name_return'] or view_dict['name']
  106. view = model == 'sell.delivery' and res.is_return and \
  107. self.env.ref(view_dict['view_return']) \
  108. or self.env.ref(view_dict['view'])
  109. if res:
  110. return {
  111. 'name': name,
  112. 'view_mode': 'form',
  113. 'view_id': False,
  114. 'views': [(view.id, 'form')],
  115. 'res_model': model,
  116. 'type': 'ir.actions.act_window',
  117. 'res_id': res.id,
  118. }
  119. raise UserError('期初余额无原始单据可查看。')
  120. class CustomerStatementsReportWithGoods(models.TransientModel):
  121. _name = "customer.statements.report.with.goods"
  122. _description = "客户对账单带商品明细"
  123. partner_id = fields.Many2one('partner', string='业务伙伴', readonly=True)
  124. name = fields.Char(string='单据编号', readonly=True)
  125. date = fields.Date(string='单据日期', readonly=True)
  126. done_date = fields.Datetime(string='完成日期', readonly=True)
  127. category_id = fields.Many2one('core.category', '商品类别')
  128. goods_code = fields.Char('商品编号')
  129. goods_name = fields.Char('商品名称')
  130. attribute_id = fields.Many2one('attribute', '规格型号')
  131. uom_id = fields.Many2one('uom', '单位')
  132. quantity = fields.Float('数量', digits='Quantity')
  133. price = fields.Float('单价', digits='Price')
  134. discount_amount = fields.Float('折扣额', digits='Amount')
  135. without_tax_amount = fields.Float(
  136. '不含税金额', digits='Amount')
  137. tax_amount = fields.Float('税额', digits='Amount')
  138. order_amount = fields.Float(
  139. string='销售金额', digits='Amount')
  140. benefit_amount = fields.Float(
  141. string='优惠金额', digits='Amount')
  142. fee = fields.Float(string='客户承担费用', digits='Amount')
  143. amount = fields.Float(string='应收金额', digits='Amount')
  144. pay_amount = fields.Float(
  145. string='实际收款金额', digits='Amount')
  146. discount_money = fields.Float(string='收款折扣', readonly=True,
  147. digits='Amount')
  148. balance_amount = fields.Float(
  149. string='应收款余额', digits='Amount')
  150. note = fields.Char(string='备注', readonly=True)
  151. move_id = fields.Many2one('wh.move', string='出入库单', readonly=True)
  152. def find_source_order(self):
  153. # 查看原始单据,三种情况:收款单、销售退货单、销售发货单
  154. self.ensure_one()
  155. model_view = {
  156. 'money.order': {'name': '收款单',
  157. 'view': 'money.money_order_form'},
  158. 'sell.delivery': {'name': '销售发货单',
  159. 'view': 'sell.sell_delivery_form',
  160. 'name_return': '销售退货单',
  161. 'view_return': 'sell.sell_return_form'},
  162. 'reconcile.order': {'name': '核销单',
  163. 'view': 'money.reconcile_order_form'}
  164. }
  165. for model, view_dict in model_view.items():
  166. res = self.env[model].search([('name', '=', self.name)])
  167. name = model == 'sell.delivery' and res.is_return and view_dict[
  168. 'name_return'] or view_dict['name']
  169. view = model == 'sell.delivery' and res.is_return and self.env.ref(view_dict['view_return']) \
  170. or self.env.ref(view_dict['view'])
  171. if res:
  172. return {
  173. 'name': name,
  174. 'view_mode': 'form',
  175. 'view_id': False,
  176. 'views': [(view.id, 'form')],
  177. 'res_model': model,
  178. 'type': 'ir.actions.act_window',
  179. 'res_id': res.id,
  180. }
  181. raise UserError('期初余额无原始单据可查看。')
上海开阖软件有限公司 沪ICP备12045867号-1