Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
3134 Переглядів

I have a Customer table inherited from Partner (id_client,some property field) a table vat (id_vat, value).Vat's tax can change over time and I need to historicize the data with two From / To fields in the relationship table (in SQl some like ID_client, ID_vat,from,to). What is the correct way to create the model and show the data in the view? 

Аватар
Відмінити
Найкраща відповідь

Use one2many or many2many field for that purpose. Both might be computed based on a date. Both might be simply shown on a view just by adding <field name='vat_ids'/>

The example if the VAT model is linked to a partner:

vat_ids = fields.One2many(
"vat.model", # the vat history model
"partner_id", # the link to partner on each line, which is updated when you update partner VAT
string="VAT History",
)

The example if the VAT model is not linked to a partner and should be somehow computed:

@api.multi
def _compute_vat_ids(self):
for partner in self:
vat_ids = [1, 2, 8] # use some logic to find vat history items by dates and partner
partner.vat_ids = [(6, 0, vat_ids)]

vat_ids = fields.Many2many(
"vat.model", # the vat history model
compute=_compute_vat_ids,
string="VAT History",
)


UPDATE

You have stated the comodel not correctly. You should apply Odoo name, not Python name

class Vat(models.Model): 
_name ='utilitypower.iva'
_description = 'Iva'
_rec_name = 'descrizione'

descrizione = fields.Char('Descrizione')
valore = fields.Integer('Valore',required=True)
anagrafica_vat_ids = fields.One2many(
'utilitypower.anagraficaiva', # NOT utilitypower.ClientsVat
'id_vat',
string='Anagrafica Iva'
)

class ClientsVat(models.Model):
_name ='utilitypower.anagraficaiva'
_description = 'Anagrafica Iva'

id_vat = fields.Many2one(
'utilitypower.iva', # NOT utilitypower.vat
string="Iva",
)
id_client= fields.Many2one(
'res.partner', # it is fine
string="Cliente",
)

#PARTNER

anagrafiche_vat_ids = fields.One2many(
'utilitypower.anagraficaiva', # NOT utilitypower.ClientsVat
'id_client',
string='Anagrafica Iva',
)


P.S. The next time please use 'code' tag to put code. Otherwise, it is not readable at all. 

Also added a like in order you can comment.

Аватар
Відмінити
Автор

thanks you're right, but I changed the name to understand the meaning of the table (iva is the vat correspondent in Italy), the model is already like you wrote.

however in the view of the client I don't have the modification and the insertion of records as usually happens with the fields of the widget one2many_list :

<field name="anagrafiche_iva_ids" string="IVA" widget="one2many_list">

<tree string="IVA assegnate" editable="top">

<field name="id_iva"></field>

<field name="dal"/>

<field name="al"/>

</tree>

</field>

Автор Найкраща відповідь

Sorry i can't comment your answer (8 karma required).. 

yes vat model is linked to a partner. I've tried to link with two one2many in relation model named PartnerVat (where i've add the 2 date fields from-to) but i can't show and manage the data fields in the view: 

class Vat(models.Model):
 _name ='utilitypower.iva'
 _description = 'Iva'
 _rec_name = 'descrizione'
 descrizione = fields.Char('Descrizione') 
 valore = fields.Integer('Valore',required=True)
 anagrafica_vat_ids = fields.One2many('utilitypower.ClientsVat','id_vat',string='Anagrafica Iva') 

 class ClientsVat(models.Model):

 _name ='utilitypower.anagraficaiva'

 _description = 'Anagrafica Iva'

 id_vat = fields.Many2one('utilitypower.vat',string="Iva")

 id_client= fields.Many2one('res.partner',string="Cliente")

from = fields.Date()    al = fields.Date() ​

to = fields.Date()

and same relation in res_partner : 

anagrafiche_vat_ids = fields.One2many('utilitypower.ClientsVat','id_client',string='Anagrafica Iva')

and in the res_partner view for show the complete data, i've tried this:

<field name="anagrafiche_iva_ids" string="IVA" widget="one2many_list"> 
 <tree string="IVA assegnate" editable="top"> 
 <field name="id_iva"></field> 
 <field name="dal"/>
 <field name="al"/> 
 </tree> 
 </field> 
but i can't add or modify the data..
I know that this is a newbie problem but i can't find how to manage the 2 adding fields, like when i add a new record or to show them in the view (so i think that my model is wrong).​
Аватар
Відмінити

Updated the answer. Look at the section 'UPDATE'

Related Posts Відповіді Переглядів Дія
1
лют. 24
2093
0
лип. 24
3143
0
лип. 22
60
1
лип. 22
3048
2
груд. 23
33566