Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
1392 Vizualizări

Hello, 

I'm trying to reuse Sales Order Wizard for creating invoice in different model but without luck. What is the best approach to reuse existing code from wizard? Is it possible to do it? 


sale_orders = self.env['sale.order'].search(domain)

wizard = self.env['sale.advance.payment.inv']
for order in sale_orders:
​invoice = wizard._create_invoices(order)

I'm ending with this error even when I print out wizard it's type sale.advance.payment.inv()


  File "/odoo-17.0+e/comunity/addons/sale/wizard/sale_make_invoice_advance.py", line 196, in _create_invoices

    self.ensure_one()

  File "/odoo-17.0+e/comunity/odoo/models.py", line 5846, in ensure_one

    raise ValueError("Expected singleton: %s" % self)

ValueError: Expected singleton: sale.advance.payment.inv()


Thx

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

Try this:sale_orders = self.env['sale.order'].search(domain)


for order in sale_orders:

    # Create a wizard for each order

    wizard = self.env['sale.advance.payment.inv'].create({

        'advance_payment_method': 'delivered',  # or 'all' depending on your needs

    })

    # Set context or any other necessary fields if required

    wizard = wizard.with_context(active_model='sale.order', active_ids=[order.id], active_id=order.id)

    # Call the method to create the invoice


Hope it helps

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
feb. 25
3189
1
feb. 24
2847
1
dec. 23
3977
1
mar. 24
2728
4
mai 25
2412