How to make a copy of a connected class?

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.__setup__ and 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?

Constantine.

Hi,
Here’s an example of a wizard to create a Purchase from a Purchase Request:
http://hg.tryton.org/modules/purchase_request/file/tip/purchase_request.py#l361

1 Like

I think you should use the sale_supply module and maybe customize the purchase_request module to group purchase based on your criteria.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.