I connected Sale Orders (SO) to Purchase Orders (PO) by Many2Many. The reason for M2M — that is possible to collect many SO to one gigantic PO or vice versa :
purchases = fields.Many2Many('purchase.purchase-sale.sale', 'sale', 'purchase', string = 'Related purchase orders', help = 'Purchase orders as the result of this sale', )
With that said, I want a user to be allowed to create a new PO based on the current SO, and then to auto-populate all fields of that ‘child’ PO with data from current SO.
I don’t understand how to do that.
Firstly, I tried to create a boolean checkmark (And I like this idea): when you check it, the on_change method should create a new PO and then populate it.
But there is the problem: I do not understand — how to create a new PO in the system?
(Once created, I can add its ID to the set in the M2M field).
May you point me to the example of how to do that correctly? I realized that there are
cls.__register__ methods, but I don’t understand how to use them. If there is a good example of creating a new record in the DB (i.e. a new class instance), that will persist in the system?