コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
2642 ビュー

I have a form with a smart button in it that takes me to another model

when I want to duplicate the current record, the content that can be seen via the smart button will not be duplicated

How to solve this ? I mean are there an existing solution or I should pass by inheriting duplicate method ?


Thank you

アバター
破棄
最善の回答

Hello Fakhri,

This is due to because the children are linked to the original parent by Id. Like you say I think the best way to do this would be to override the copy function on the parent object and then search for all children which relate to the original parent. Then for each child, duplicate and change the many2one to link to the new record which you have just duplicated. 

Here is an example for duplicating a parent and copy all CRM records from the old to new:

class odoo_help_4(models.Model):
    _inherit = "res.partner"
    def copy(self, default=None):
        new = super(odoo_help_4, self).copy(default=default)
        # get all deals which are equal to old
        all_crms = self.env["crm.lead"].search([("partner_id", "=", self.id)])
        # duplicate all deals and change the partner_id to the new id
        for crm in all_crms:
            crm.copy({"partner_id": new.id})
        return new
I hope this helps,

Thanks, 
アバター
破棄
著作者

as you said Jack i should pass by overriding copy method.

Anyway think it will be very useful if copy method will take this case in consideration on odoo next versions

関連投稿 返信 ビュー 活動
3
8月 24
15438
2
6月 23
4305
0
10月 17
2606
1
7月 16
10824
0
3月 15
3801