GoodERP
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

196 lines
8.6KB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from odoo import _
  22. from odoo import fields, models, api, tools
  23. from odoo.exceptions import UserError
  24. class CustomerStatementsReport(models.Model):
  25. _inherit = "customer.statements.report"
  26. _auto = False
  27. sale_amount = fields.Float(string='销售金额', readonly=True,
  28. digits='Amount')
  29. benefit_amount = fields.Float(string='优惠金额', readonly=True,
  30. digits='Amount')
  31. fee = fields.Float(string='客户承担费用', readonly=True,
  32. digits='Amount')
  33. move_id = fields.Many2one('wh.move', string='出入库单', readonly=True)
  34. def init(self):
  35. # union money_order(type = 'get'), money_invoice(type = 'income')
  36. cr = self._cr
  37. tools.drop_view_if_exists(cr, 'customer_statements_report')
  38. cr.execute("""
  39. CREATE or REPLACE VIEW customer_statements_report AS (
  40. SELECT ROW_NUMBER() OVER(ORDER BY partner_id, date, amount desc) AS id,
  41. partner_id,
  42. name,
  43. date,
  44. done_date,
  45. sale_amount,
  46. benefit_amount,
  47. fee,
  48. amount,
  49. pay_amount,
  50. discount_money,
  51. balance_amount,
  52. note,
  53. move_id
  54. FROM
  55. (
  56. SELECT m.partner_id,
  57. m.name,
  58. m.date,
  59. m.write_date AS done_date,
  60. 0 AS sale_amount,
  61. 0 AS benefit_amount,
  62. 0 AS fee,
  63. 0 AS amount,
  64. m.amount AS pay_amount,
  65. m.discount_amount as discount_money,
  66. 0 AS balance_amount,
  67. m.note,
  68. 0 AS move_id
  69. FROM money_order AS m
  70. WHERE m.type = 'get' AND m.state = 'done'
  71. UNION ALL
  72. SELECT mi.partner_id,
  73. mi.name,
  74. mi.date,
  75. mi.create_date AS done_date,
  76. sd.amount + sd.discount_amount AS sale_amount,
  77. sd.discount_amount AS benefit_amount,
  78. sd.partner_cost AS fee,
  79. mi.amount,
  80. 0 AS pay_amount,
  81. 0 as discount_money,
  82. 0 AS balance_amount,
  83. Null AS note,
  84. mi.move_id
  85. FROM money_invoice AS mi
  86. LEFT JOIN core_category AS c ON mi.category_id = c.id
  87. LEFT JOIN sell_delivery AS sd ON sd.sell_move_id = mi.move_id
  88. WHERE c.type = 'income' AND mi.state = 'done'
  89. ) AS ps)
  90. """)
  91. def find_source_order(self):
  92. # 查看原始单据,三种情况:收款单、销售退货单、销售发货单、核销单
  93. self.ensure_one()
  94. model_view = {
  95. 'money.order': {'name': _('收款单'),
  96. 'view': 'money.money_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.delivery': {'name': _('销售发货单'),
  161. 'view': 'sell.sell_delivery_form',
  162. 'name_return': _('销售退货单'),
  163. 'view_return': 'sell.sell_return_form'},
  164. 'reconcile.order': {'name': _('核销单'),
  165. 'view': 'money.reconcile_order_form'}
  166. }
  167. for model, view_dict in model_view.items():
  168. res = self.env[model].search([('name', '=', self.name)])
  169. name = model == 'sell.delivery' and res.is_return and view_dict[
  170. 'name_return'] or view_dict['name']
  171. view = model == 'sell.delivery' and res.is_return and self.env.ref(view_dict['view_return']) \
  172. or self.env.ref(view_dict['view'])
  173. if res:
  174. return {
  175. 'name': name,
  176. 'view_mode': 'form',
  177. 'view_id': False,
  178. 'views': [(view.id, 'form')],
  179. 'res_model': model,
  180. 'type': 'ir.actions.act_window',
  181. 'res_id': res.id,
  182. }
  183. raise UserError(_('期初余额无原始单据可查看。'))
上海开阖软件有限公司 沪ICP备12045867号-1