Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
6281 Widoki

I am trying to view the record made by using .copy(values) method. In a broader sense, I am trying to implement version control on my products. 

Example: Product 01v1 -> Product 01v2 


def do_product_revision(self):
        for cur_rec in self:
            ## Create a new version to work on, and auto generate name
            # Generate new version number
            ver_no = cur_rec.ver_no + 1

            # Update the product name P1-v01 to P1-v02, and version number from 1 -> 2
            vals = {
                'name': cur_rec.name.split("-")[0] + '-v%01d'%(ver_no),
                'ver_no': ver_no,
            }
               
            # Copy old record, but with new name and version number into new_record.
            new_record = cur_rec.copy(default=vals) ## How to open view of this record?!


I would like to know how I would open a (form) view of this new_record. How do I refer to it in the view.xml? How does my .xml know what id this brand new copy has?



Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

You can try something like this,

def do_product_revision(self):
for cur_rec in self:
## Create a new version to work on, and auto generate name
# Generate new version number
ver_no = cur_rec.ver_no + 1

# Update the product name P1-v01 to P1-v02, and version number from 1 -> 2
vals = {
'name': cur_rec.name.split("-")[0] + '-v%01d' % (ver_no),
'ver_no': ver_no,
}

# Copy old record, but with new name and version number into new_record.
new_record = cur_rec.copy(default=vals) ## How to open view of this record?!
return {
'type': 'ir.actions.act_window',
'res_model': 'Model_name_to_open',
'res_id': new_record.id,
'view_mode': 'form',
'target': 'new',
}

Thanks

Awatar
Odrzuć
Autor

It worked! Thanks so much! I prefer removing the 'target' such that it doesnt open a pop-up. Learned another thing today!

Powiązane posty Odpowiedzi Widoki Czynność
0
lut 22
3269
3
wrz 24
2852
2
wrz 25
651
1
paź 25
755
2
cze 25
2314