Skip to Content
Menú
This question has been flagged
1931 Vistes

I have this code in odoo 16:

from odoo import models, fields, api



class AccountMove(models.Model):

     _inherit = 'account.move'


     def merge_invoice_lines(self):

         for invoice in self:

             lines_dict = {}

             lines_to_remove = self.env['account\.move\.line'\]


 \  \  \  \  \  \  for\ line\ in\ invoice\.invoice_line_ids:

 \  \  \  \  \  \  \  \  if\ line\.product_id\.id\ in\ lines_dict:

 \  \  \  \  \  \  \  \  \  \  \#\ If\ the\ product\ already\ exists,\ add\ the\ quantities\ and\ delete\ the\ original\ line\.

 \  \  \  \  \  \  \  \  \  \  lines_dict\[line\.product_id\.id\]\.quantity\ \+=\ line\.quantity

 \  \  \  \  \  \  \  \  \  \  lines_to_remove\ \+=\ line

 \  \  \  \  \  \  \  \  else:

 \  \  \  \  \  \  \  \  \  \  lines_dict\[line\.product_id\.id\]\ =\ line


 \  \  \  \  \  \  \#\ Delete\ the\ original\ invoice\ lines

 \  \  \  \  \  \  invoice\.invoice_line_ids\ \-=\ lines_to_remove


 \  \  \  \  \  \  \#\ Add\ the\ merged\ lines\ back\ to\ the\ invoice

 \  \  \  \  \  \  for\ product_id,\ line\ in\ lines_dict\.items\(\):

 \  \  \  \  \  \  \  \  invoice\.invoice_line_ids\ \+=\ line


 \  \  \  \  return\ True

and\ this\ in\ xml: 

 \  \  

 \  \  \  \  

 \  \  \  \  ir\.ui\.view">

 \  \  \  \  \  \  account.invoice.form.merge.button

             account.move

             

             

                 

                     

                 

             

         

     


What I am trying to do is the following: I make 4 sales orders, the 4 orders have the same customer and the same products (which are 4 products, snacks, chocolates, juices, soft drinks) but with different quantities, I select the 4 sales orders. sale and I make an invoice in which the invoice shows me all the products that have the 4 sales orders only on the invoice, until then everything is fine... on the invoice there is a button to access the 4 sales orders where the invoice was generated, the method is called action_view_source_sale_orders, now, on the invoice when I click on the button called "Merge repeated lines", the products are merged without problem, BUT it alters the action_view_source_sale_orders button, because When I merge the repeated products of the invoice, in the other button where it shows the sales orders, instead of being 4 orders there are now 2... how can I prevent the action_view_source_sale_orders method from being altered and not eliminating the sales orders?

Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
de nov. 23
1479
1
d’abr. 24
3474
1
d’oct. 22
3567
4
de juny 20
4422
1
de març 15
4967