GoodERP
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

198 lines
8.7KB

  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.order': {'name': '销售订单',
  96. 'view': 'sell.sell_order_form'},
  97. 'sell.delivery': {'name': '销售发货单',
  98. 'view': 'sell.sell_delivery_form',
  99. 'name_return': '销售退货单',
  100. 'view_return': 'sell.sell_return_form'},
  101. 'reconcile.order': {'name': '核销单',
  102. 'view': 'money.reconcile_order_form'}
  103. }
  104. for model, view_dict in model_view.items():
  105. res = self.env[model].search([('name', '=', self.name)])
  106. name = model == 'sell.delivery' and res.is_return and \
  107. view_dict['name_return'] or view_dict['name']
  108. view = model == 'sell.delivery' and res.is_return and \
  109. self.env.ref(view_dict['view_return']) \
  110. or self.env.ref(view_dict['view'])
  111. if res:
  112. return {
  113. 'name': name,
  114. 'view_mode': 'form',
  115. 'view_id': False,
  116. 'views': [(view.id, 'form')],
  117. 'res_model': model,
  118. 'type': 'ir.actions.act_window',
  119. 'res_id': res.id,
  120. }
  121. raise UserError('期初余额无原始单据可查看。')
  122. class CustomerStatementsReportWithGoods(models.TransientModel):
  123. _name = "customer.statements.report.with.goods"
  124. _description = "客户对账单带商品明细"
  125. partner_id = fields.Many2one('partner', string='业务伙伴', readonly=True)
  126. name = fields.Char(string='单据编号', readonly=True)
  127. date = fields.Date(string='单据日期', readonly=True)
  128. done_date = fields.Datetime(string='完成日期', readonly=True)
  129. category_id = fields.Many2one('core.category', '商品类别')
  130. goods_code = fields.Char('商品编号')
  131. goods_name = fields.Char('商品名称')
  132. attribute_id = fields.Many2one('attribute', '规格型号')
  133. uom_id = fields.Many2one('uom', '单位')
  134. quantity = fields.Float('数量', digits='Quantity')
  135. price = fields.Float('单价', digits='Price')
  136. discount_amount = fields.Float('折扣额', digits='Amount')
  137. without_tax_amount = fields.Float(
  138. '不含税金额', digits='Amount')
  139. tax_amount = fields.Float('税额', digits='Amount')
  140. order_amount = fields.Float(
  141. string='销售金额', digits='Amount')
  142. benefit_amount = fields.Float(
  143. string='优惠金额', digits='Amount')
  144. fee = fields.Float(string='客户承担费用', digits='Amount')
  145. amount = fields.Float(string='应收金额', digits='Amount')
  146. pay_amount = fields.Float(
  147. string='实际收款金额', digits='Amount')
  148. discount_money = fields.Float(string='收款折扣', readonly=True,
  149. digits='Amount')
  150. balance_amount = fields.Float(
  151. string='应收款余额', digits='Amount')
  152. note = fields.Char(string='备注', readonly=True)
  153. move_id = fields.Many2one('wh.move', string='出入库单', readonly=True)
  154. def find_source_order(self):
  155. # 查看原始单据,三种情况:收款单、销售退货单、销售发货单
  156. self.ensure_one()
  157. model_view = {
  158. 'money.order': {'name': '收款单',
  159. 'view': 'money.money_order_form'},
  160. 'sell.order': {'name': '销售订单',
  161. 'view': 'sell.sell_order_form'},
  162. 'sell.delivery': {'name': '销售发货单',
  163. 'view': 'sell.sell_delivery_form',
  164. 'name_return': '销售退货单',
  165. 'view_return': 'sell.sell_return_form'},
  166. 'reconcile.order': {'name': '核销单',
  167. 'view': 'money.reconcile_order_form'}
  168. }
  169. for model, view_dict in model_view.items():
  170. res = self.env[model].search([('name', '=', self.name)])
  171. name = model == 'sell.delivery' and res.is_return and view_dict[
  172. 'name_return'] or view_dict['name']
  173. view = model == 'sell.delivery' and res.is_return and self.env.ref(view_dict['view_return']) \
  174. or self.env.ref(view_dict['view'])
  175. if res:
  176. return {
  177. 'name': name,
  178. 'view_mode': 'form',
  179. 'view_id': False,
  180. 'views': [(view.id, 'form')],
  181. 'res_model': model,
  182. 'type': 'ir.actions.act_window',
  183. 'res_id': res.id,
  184. }
  185. raise UserError('期初余额无原始单据可查看。')
上海开阖软件有限公司 沪ICP备12045867号-1