Skip to Content
Menú
This question has been flagged
1 Respondre
2446 Vistes

Problem Description:

I am building a form using Odoo Studio. The form has two section (Similar to sales form). In the top section I have three fields namely:

  • L
  • W
  • A (This is computed field = L x W)

The Value of A is calculated successfully. Below that I have a list (similar to order lines in sales order). The list has Five fields as follows:

  • Material (a text field, manual input)
  • MPA (decimal field, manual input similar to price in sales order line)
  • TM (decimal field, calculated = MPA x A)

As evident, the calculation of TM uses a field A which belongs to a different model. I am unable to perform this calculation.

How I have Tried to Solve It

I have used Odoo Studio and adopted the following approach:

In the compute of TM field I have added the following code:

for record in self:
    record['TM'] = record.A * record.MPA

Version Information

Odoo Online Version 16.04+e(Enterprise)


Any help to resolve this issue will be much appreciated.

Regards.

Avatar
Descartar
Best Answer

Hello @Abrar Asghar 


I hope you are doing well,


First of all, for you to access the element of a different module there should be some relation between both for example take a look the sales form in odoo standard, here the relation is one2many in sale.order model and many2one in sale.order.line model.


- As described you have 3 fields(L, W, A) where A is compute (L x W).


Now in the list below(Order lines) again there are 3 fields (Material, MPA, TM) and TM needs to be the compute of MPA and A from above.

Please find code in comment. 

Hope this answer helps you.

Thanks & Regards,
Email: odoo@aktivsoftware.com     

Skype: kalpeshmaheshwari

Avatar
Descartar

Please find code here :-

For the compute to work correctly you need to write the compute on TM as below.

def compute_method_name(self):
for record in self:
record.TM = record.m2o_field.A * record.MPA

Related Posts Respostes Vistes Activitat
1
de febr. 25
1256
4
de gen. 24
1786
1
de maig 21
4423
1
de juny 25
15211
3
d’abr. 25
5323