From 719a96d5fc7373f9c5e4e97a15f17f53f26d7a4b Mon Sep 17 00:00:00 2001 From: Juliana Date: Wed, 18 Dec 2019 10:44:49 +0100 Subject: [PATCH] test 3 --- models/sale_order.py | 96 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 7 deletions(-) diff --git a/models/sale_order.py b/models/sale_order.py index c921e17..d844808 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -13,19 +13,101 @@ class SaleOrder(models.Model): lambda t: not t.pack_parent_line_id.exists(), ) - @api.multi - def action_invoice_create(self, grouped=False, final=False): - res = super(SaleOrder, self).action_invoice_create( - grouped, final) - print("----- TEST ------", str(res)) - return res - +# @api.multi +# def action_invoice_create(self, grouped=False, final=False): +# """ +# Create the invoice associated to the SO. +# :param grouped: if True, invoices are grouped by SO id. If False, invoices are grouped by +# (partner_invoice_id, currency) +# :param final: if True, refunds will be generated if necessary +# :returns: list of created invoices +# """ +# res = super(SaleOrder, self).action_invoice_create(grouped, final) +# inv_obj = self.env['account.invoice'] +# precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') +# invoices = {} +# references = {} +# invoices_origin = {} +# invoices_name = {} + +# for order in self: +# group_key = order.id if grouped else (order.partner_invoice_id.id, order.currency_id.id) + +# # We only want to create sections that have at least one invoiceable line +# pending_section = None + +# for line in order.order_line: +# print("---line---", str(line)) +# if line.display_type == 'line_section': +# pending_section = line +# continue +# if group_key not in invoices: +# inv_data = order._prepare_invoice() +# invoice = inv_obj.create(inv_data) +# references[invoice] = order +# invoices[group_key] = invoice +# invoices_origin[group_key] = [invoice.origin] +# invoices_name[group_key] = [invoice.name] +# elif group_key in invoices: +# if order.name not in invoices_origin[group_key]: +# invoices_origin[group_key].append(order.name) +# if order.client_order_ref and order.client_order_ref not in invoices_name[group_key]: +# invoices_name[group_key].append(order.client_order_ref) + +# if line.qty_to_invoice > 0 or (line.qty_to_invoice < 0 and final): +# print("---invoice lune create---", str(line)) +# if pending_section: +# pending_section.invoice_line_create(invoices[group_key].id, pending_section.qty_to_invoice) +# pending_section = None +# line.invoice_line_create(invoices[group_key].id, line.qty_to_invoice) + +# if references.get(invoices.get(group_key)): +# if order not in references[invoices[group_key]]: +# references[invoices[group_key]] |= order + +# for group_key in invoices: +# invoices[group_key].write({'name': ', '.join(invoices_name[group_key]), +# 'origin': ', '.join(invoices_origin[group_key])}) +# sale_orders = references[invoices[group_key]] +# if len(sale_orders) == 1: +# invoices[group_key].reference = sale_orders.reference + +# # if not invoices: +# # 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.')) + +# for invoice in invoices.values(): +# print("--- invoice ---", str(invoice)) +# invoice.compute_taxes() +# if not invoice.invoice_line_ids: +# 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.')) +# # If invoice is negative, do a refund invoice instead +# if invoice.amount_total < 0: +# invoice.type = 'out_refund' +# for line in invoice.invoice_line_ids: +# line.quantity = -line.quantity +# # Use additional field helper function (for account extensions) +# for line in invoice.invoice_line_ids: +# line._set_additional_fields(invoice) +# # Necessary to force computation of taxes. In account_invoice, they are triggered +# # by onchanges, which are not triggered when doing a create. +# invoice.compute_taxes() +# # Idem for partner +# so_payment_term_id = invoice.payment_term_id.id +# invoice._onchange_partner_id() +# # To keep the payment terms set on the SO +# invoice.payment_term_id = so_payment_term_id +# invoice.message_post_with_view('mail.message_origin_link', +# values={'self': invoice, 'origin': references[invoice]}, +# subtype_id=self.env.ref('mail.mt_note').id) +# return [inv.id for inv in invoices.values()] + class SaleOrderLine(models.Model): _inherit = "sale.order.line" @api.multi def invoice_line_create(self, invoice_id, qty): + print("---- TEST ----", str(invoice_id)) invoice_lines = super(SaleOrderLine, self).invoice_line_create( invoice_id, qty) print("---- invoice_lines ----", str(invoice_lines))