콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
1049 화면

I have multiple sales orders for a project.  I am trying to create a field on the project form card that will total all of the untaxed amounts on the sales orders.  I have created a One2Many field to show the list of all of the sales orders but can't figure out how to get a field on the Project form to total from the sub list.  Can anyone help?

아바타
취소
베스트 답변

Hi Doug,

You can add computed field in project and the computed method will loop the sale orders and save the total to the the computed field as below:


total_sale_amount_untaxed = fields.Monetary(string='Total Sale Untaxed Amount', store=True, compute='_compute_untaxed_amount')

@api.depends('sale_order_ids') # replace sale_order_ids with the One2many which you created to retrieve sale orders

def _compute_untaxed_amount(self):
for project in self:
total_amount = 0.0
for order in project.sale_order_ids:
total_amount += order.amount_untaxed
project.total_sale_amount_untaxed = total_amount

Note: The above code will work if you are using one currency but if you are using multi currency then you need to convert the sale order with secondary currency to the company currency.

아바타
취소