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.

135 lines
7.0 KiB

5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
  1. # © 2019 Le Filament (<http://www.le-filament.com>)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import models, fields, api
  4. class SaleOrder(models.Model):
  5. _inherit = "sale.order"
  6. @api.one
  7. def _compute_website_order_line(self):
  8. self.website_order_line = self.order_line.filtered(
  9. lambda t: not t.pack_parent_line_id.exists(),
  10. )
  11. @api.multi
  12. def action_invoice_create(self, grouped=False, final=False):
  13. res = super(SaleOrder, self).action_invoice_create(grouped, final)
  14. print("------ res ------", str(res))
  15. print("------ grouped ------", str(grouped))
  16. print("------ final ------", str(final))
  17. return res
  18. # """
  19. # Create the invoice associated to the SO.
  20. # :param grouped: if True, invoices are grouped by SO id. If False, invoices are grouped by
  21. # (partner_invoice_id, currency)
  22. # :param final: if True, refunds will be generated if necessary
  23. # :returns: list of created invoices
  24. # """
  25. # res = super(SaleOrder, self).action_invoice_create(grouped, final)
  26. # inv_obj = self.env['account.invoice']
  27. # precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
  28. # invoices = {}
  29. # references = {}
  30. # invoices_origin = {}
  31. # invoices_name = {}
  32. # for order in self:
  33. # group_key = order.id if grouped else (order.partner_invoice_id.id, order.currency_id.id)
  34. # # We only want to create sections that have at least one invoiceable line
  35. # pending_section = None
  36. # for line in order.order_line:
  37. # print("---line---", str(line))
  38. # if line.display_type == 'line_section':
  39. # pending_section = line
  40. # continue
  41. # if group_key not in invoices:
  42. # inv_data = order._prepare_invoice()
  43. # invoice = inv_obj.create(inv_data)
  44. # references[invoice] = order
  45. # invoices[group_key] = invoice
  46. # invoices_origin[group_key] = [invoice.origin]
  47. # invoices_name[group_key] = [invoice.name]
  48. # elif group_key in invoices:
  49. # if order.name not in invoices_origin[group_key]:
  50. # invoices_origin[group_key].append(order.name)
  51. # if order.client_order_ref and order.client_order_ref not in invoices_name[group_key]:
  52. # invoices_name[group_key].append(order.client_order_ref)
  53. # if line.qty_to_invoice > 0 or (line.qty_to_invoice < 0 and final):
  54. # print("---invoice lune create---", str(line))
  55. # if pending_section:
  56. # pending_section.invoice_line_create(invoices[group_key].id, pending_section.qty_to_invoice)
  57. # pending_section = None
  58. # line.invoice_line_create(invoices[group_key].id, line.qty_to_invoice)
  59. # if references.get(invoices.get(group_key)):
  60. # if order not in references[invoices[group_key]]:
  61. # references[invoices[group_key]] |= order
  62. # for group_key in invoices:
  63. # invoices[group_key].write({'name': ', '.join(invoices_name[group_key]),
  64. # 'origin': ', '.join(invoices_origin[group_key])})
  65. # sale_orders = references[invoices[group_key]]
  66. # if len(sale_orders) == 1:
  67. # invoices[group_key].reference = sale_orders.reference
  68. # # if not invoices:
  69. # # raise UserError(_('There is no invoiceable line. If a product has a Delivered quantities invoicing policy, please make sure that a quantity has been delivered.'))
  70. # for invoice in invoices.values():
  71. # print("--- invoice ---", str(invoice))
  72. # invoice.compute_taxes()
  73. # if not invoice.invoice_line_ids:
  74. # raise UserError(_('There is no invoiceable line. If a product has a Delivered quantities invoicing policy, please make sure that a quantity has been delivered.'))
  75. # # If invoice is negative, do a refund invoice instead
  76. # if invoice.amount_total < 0:
  77. # invoice.type = 'out_refund'
  78. # for line in invoice.invoice_line_ids:
  79. # line.quantity = -line.quantity
  80. # # Use additional field helper function (for account extensions)
  81. # for line in invoice.invoice_line_ids:
  82. # line._set_additional_fields(invoice)
  83. # # Necessary to force computation of taxes. In account_invoice, they are triggered
  84. # # by onchanges, which are not triggered when doing a create.
  85. # invoice.compute_taxes()
  86. # # Idem for partner
  87. # so_payment_term_id = invoice.payment_term_id.id
  88. # invoice._onchange_partner_id()
  89. # # To keep the payment terms set on the SO
  90. # invoice.payment_term_id = so_payment_term_id
  91. # invoice.message_post_with_view('mail.message_origin_link',
  92. # values={'self': invoice, 'origin': references[invoice]},
  93. # subtype_id=self.env.ref('mail.mt_note').id)
  94. # return [inv.id for inv in invoices.values()]
  95. class SaleOrderLine(models.Model):
  96. _inherit = "sale.order.line"
  97. @api.multi
  98. def invoice_line_create(self, invoice_id, qty):
  99. print("---- TEST sans rien----")
  100. print("---- TEST ----", str(invoice_id))
  101. invoice_lines = super(SaleOrderLine, self).invoice_line_create(
  102. invoice_id, qty)
  103. print("---- invoice_lines ----", str(invoice_lines))
  104. return invoice_lines
  105. # invoice_lines = self.env['account.invoice.line']
  106. # for line in self:
  107. # # Check if line has a pack_parent_line_id
  108. # print("---- self.pack_parent_line_id.exists() -----", str(self.pack_parent_line_id.exists()))
  109. # if self.pack_parent_line_id.exists():
  110. # # Get the ref of parent pack
  111. # sale_id_ref = self.env['sale.order.line'].search([('id', '=', self.pack_parent_line_id.id)])
  112. # print("--- sale_id_ref ---", str(sale_id_ref))
  113. # print("--- sale_id_ref.product_id.product_tmpl_id.pack_type ---", str(sale_id_ref.product_id.product_tmpl_id.pack_type))
  114. # print("--- sale_id_ref.product_id.product_tmpl_id.pack_component_price ---", str(sale_id_ref.product_id.product_tmpl_id.pack_component_price))
  115. # # Check if product is Pack detailed and option Totalized
  116. # if sale_id_ref.product_id.product_tmpl_id.pack_type == 'detailed' and sale_id_ref.product_id.product_tmpl_id.pack_component_price == 'totalized':
  117. # return invoice_lines
  118. # invoice_lines = super(SaleOrderLine, self).invoice_line_create(
  119. # invoice_id, qty)
  120. # return invoice_lines