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
2456 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć

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

Powiązane posty Odpowiedzi Widoki Czynność
1
lut 25
1267
4
sty 24
1793
1
maj 21
4428
1
cze 25
15229
3
kwi 25
5349