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.

129 lines
6.7 KiB

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