Skip to Content
मेन्यू
This question has been flagged
1 Reply
1013 Views

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
1
फ़र॰ 24
5202
1
जन॰ 24
2228
1
दिस॰ 22
3396
2
अग॰ 21
3061
1
अग॰ 21
2619