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.

145 lines
7.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import time
  4. from odoo import api, fields, models, _
  5. from odoo.addons import decimal_precision as dp
  6. from odoo.exceptions import UserError
  7. class SaleAdvancePaymentInv(models.TransientModel):
  8. _inherit = "sale.advance.payment.inv"
  9. @api.multi
  10. def _create_invoice(self, order, so_line, amount):
  11. print("---- _create_invoice ----")
  12. return super(SaleAdvancePaymentInv, self)._create_invoice(order, so_line, amount)
  13. # inv_obj = self.env['account.invoice']
  14. # ir_property_obj = self.env['ir.property']
  15. # account_id = False
  16. # if self.product_id.id:
  17. # account_id = self.product_id.property_account_income_id.id or self.product_id.categ_id.property_account_income_categ_id.id
  18. # if not account_id:
  19. # inc_acc = ir_property_obj.get('property_account_income_categ_id', 'product.category')
  20. # account_id = order.fiscal_position_id.map_account(inc_acc).id if inc_acc else False
  21. # if not account_id:
  22. # raise UserError(
  23. # _('There is no income account defined for this product: "%s". You may have to install a chart of account from Accounting app, settings menu.') %
  24. # (self.product_id.name,))
  25. # if self.amount <= 0.00:
  26. # raise UserError(_('The value of the down payment amount must be positive.'))
  27. # context = {'lang': order.partner_id.lang}
  28. # if self.advance_payment_method == 'percentage':
  29. # amount = order.amount_untaxed * self.amount / 100
  30. # name = _("Down payment of %s%%") % (self.amount,)
  31. # else:
  32. # amount = self.amount
  33. # name = _('Down Payment')
  34. # del context
  35. # taxes = self.product_id.taxes_id.filtered(lambda r: not order.company_id or r.company_id == order.company_id)
  36. # if order.fiscal_position_id and taxes:
  37. # tax_ids = order.fiscal_position_id.map_tax(taxes, self.product_id, order.partner_shipping_id).ids
  38. # else:
  39. # tax_ids = taxes.ids
  40. # invoice = inv_obj.create({
  41. # 'name': order.client_order_ref or order.name,
  42. # 'origin': order.name,
  43. # 'type': 'out_invoice',
  44. # 'reference': False,
  45. # 'account_id': order.partner_id.property_account_receivable_id.id,
  46. # 'partner_id': order.partner_invoice_id.id,
  47. # 'partner_shipping_id': order.partner_shipping_id.id,
  48. # 'invoice_line_ids': [(0, 0, {
  49. # 'name': name,
  50. # 'origin': order.name,
  51. # 'account_id': account_id,
  52. # 'price_unit': amount,
  53. # 'quantity': 1.0,
  54. # 'discount': 0.0,
  55. # 'uom_id': self.product_id.uom_id.id,
  56. # 'product_id': self.product_id.id,
  57. # 'sale_line_ids': [(6, 0, [so_line.id])],
  58. # 'invoice_line_tax_ids': [(6, 0, tax_ids)],
  59. # 'analytic_tag_ids': [(6, 0, so_line.analytic_tag_ids.ids)],
  60. # 'account_analytic_id': order.analytic_account_id.id or False,
  61. # })],
  62. # 'currency_id': order.pricelist_id.currency_id.id,
  63. # 'payment_term_id': order.payment_term_id.id,
  64. # 'fiscal_position_id': order.fiscal_position_id.id or order.partner_id.property_account_position_id.id,
  65. # 'team_id': order.team_id.id,
  66. # 'user_id': order.user_id.id,
  67. # 'comment': order.note,
  68. # })
  69. # invoice.compute_taxes()
  70. # invoice.message_post_with_view('mail.message_origin_link',
  71. # values={'self': invoice, 'origin': order},
  72. # subtype_id=self.env.ref('mail.mt_note').id)
  73. # return invoice
  74. @api.multi
  75. def create_invoices(self):
  76. print("---- create_invoices ----")
  77. return super(SaleAdvancePaymentInv, self).create_invoices()
  78. # sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', []))
  79. # if self.advance_payment_method == 'delivered':
  80. # sale_orders.action_invoice_create()
  81. # elif self.advance_payment_method == 'all':
  82. # sale_orders.action_invoice_create(final=True)
  83. # else:
  84. # # Create deposit product if necessary
  85. # if not self.product_id:
  86. # vals = self._prepare_deposit_product()
  87. # self.product_id = self.env['product.product'].create(vals)
  88. # self.env['ir.config_parameter'].sudo().set_param('sale.default_deposit_product_id', self.product_id.id)
  89. # sale_line_obj = self.env['sale.order.line']
  90. # for order in sale_orders:
  91. # if self.advance_payment_method == 'percentage':
  92. # amount = order.amount_untaxed * self.amount / 100
  93. # else:
  94. # amount = self.amount
  95. # if self.product_id.invoice_policy != 'order':
  96. # raise UserError(_('The product used to invoice a down payment should have an invoice policy set to "Ordered quantities". Please update your deposit product to be able to create a deposit invoice.'))
  97. # if self.product_id.type != 'service':
  98. # raise UserError(_("The product used to invoice a down payment should be of type 'Service'. Please use another product or update this product."))
  99. # taxes = self.product_id.taxes_id.filtered(lambda r: not order.company_id or r.company_id == order.company_id)
  100. # if order.fiscal_position_id and taxes:
  101. # tax_ids = order.fiscal_position_id.map_tax(taxes, self.product_id, order.partner_shipping_id).ids
  102. # else:
  103. # tax_ids = taxes.ids
  104. # context = {'lang': order.partner_id.lang}
  105. # analytic_tag_ids = []
  106. # for line in order.order_line:
  107. # analytic_tag_ids = [(4, analytic_tag.id, None) for analytic_tag in line.analytic_tag_ids]
  108. # so_line = sale_line_obj.create({
  109. # 'name': _('Advance: %s') % (time.strftime('%m %Y'),),
  110. # 'price_unit': amount,
  111. # 'product_uom_qty': 0.0,
  112. # 'order_id': order.id,
  113. # 'discount': 0.0,
  114. # 'product_uom': self.product_id.uom_id.id,
  115. # 'product_id': self.product_id.id,
  116. # 'analytic_tag_ids': analytic_tag_ids,
  117. # 'tax_id': [(6, 0, tax_ids)],
  118. # 'is_downpayment': True,
  119. # })
  120. # del context
  121. # self._create_invoice(order, so_line, amount)
  122. # if self._context.get('open_invoices', False):
  123. # return sale_orders.action_view_invoice()
  124. # return {'type': 'ir.actions.act_window_close'}
  125. # def _prepare_deposit_product(self):
  126. # return {
  127. # 'name': 'Down payment',
  128. # 'type': 'service',
  129. # 'invoice_policy': 'order',
  130. # 'property_account_income_id': self.deposit_account_id.id,
  131. # 'taxes_id': [(6, 0, self.deposit_taxes_id.ids)],
  132. # 'company_id': False,
  133. # }