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

I have been able to create a model with a sequence code that successfully generates when I create a record directly from the model's view. However, attempting to do the same from a One2many tree view fails to generate the code which in turn does not allow a user to create the record.


Create function:

    def create(self, vals):
obj = super(Beneficiary,self).create(vals)
if obj.code == _("New"):
number = self.env["ir.sequence"].get('beneficiary') or _("New")
obj.write({'code':number})

return obj

Tree Definition:

<page string="Beneficiaries">
<field name="beneficiary_training" nolabel="1">
<tree string="Beneficiaries">
<field name="code"/>
<field name="id_number"/>
<field name="number"/>
</tree>
</field>
</page>



Awatar
Odrzuć
Autor

I am using Odoo Version 13

Did you set a default value for code? How? You can do this via the one2many field context attribute. See how we do it for the invoice_line_ids field on an Invoice. We define a default partner_id to populate on each journal item order_id to each line. context="{'default_partner_id': commercial_partner_id}"

Autor

Hey @Ray. Yes, I've used a default in code as shown below:

code = fields.Char(

string="Beneficiary No.",

required=True,

default=lambda self: _("New"),

track_visibility="onchange",

copy=False,

help="ID used for internal beneficiary tracking tracking.")

I'm not looking to use a default code, the goal is that one can create a new record through a one2many tree and the sequence numbers will continue generating in the same order.

Najlepsza odpowiedź

The sequence will be created as soon as you click on the Save button of the main record.

I think you are expecting to have the sequence when you add a line in o2m without clicking on the Save button. If yes, you should use the onchange method or set as default (as Ray said) to set the sequence.

Awatar
Odrzuć
Autor

Thanks @Sudhir. Grateful for the help.

Powiązane posty Odpowiedzi Widoki Czynność
1
sty 25
1833
2
wrz 22
9591
2
kwi 22
4632
0
lip 21
7278
1
mar 21
5019