跳至内容
菜单
此问题已终结
1 回复
1036 查看

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},        }

形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
2月 24
5345
1
1月 24
2274
1
12月 22
3425
2
8月 21
3096
1
8月 21
2667