Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1007 Vistas

I have 2 models: SO and Invoicing. I want to create single Invoice from single SO. Please help me ~~


    def action_create_invoice(self):        

​self.ensure_one()        

​return {

            "name": _("Create invoicing"),

            "res_model": "pma.invoicing",

            "type": "ir.actions.act_window", 

            "view_mode": "form",

            "view_type": "form",

            "target": "current",

            "context": {"create": False, "default_service_order": self.id},        }

Avatar
Descartar
Mejor respuesta

Hi,


Try this code:


def action_create_invoice(self):


        self.ensure_one()


        # Create an invoice record with a link to the current Sales Order


        invoice_vals = {


            'service_order_id': self.id,  # Assuming the field name is 'service_order_id'


            # ... other fields for the invoice ...


        }


        # Create the invoice record


        new_invoice = self.env['pma.invoicing'].create(invoice_vals)


        # Return the action to open the created invoice in form view


        return {


            'name': _("Create Invoicing"),


            'res_model': 'pma.invoicing',


            'type': 'ir.actions.act_window',


            'view_mode': 'form',


            'view_type': 'form',


            'res_id': new_invoice.id,  # Open the form view of the newly created invoice


            'target': 'current',


        }




Hope it helps

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
feb 24
5193
1
ene 24
2226
1
dic 22
3393
2
ago 21
3059
1
ago 21
2617