Skip to Content
Menu
This question has been flagged
1 Reply
2571 Views

Hi,

I wanto to create in res.partner field (like:partner_order_total_amount) for calculate partner's total amount of uninvoiced sales orders.


For example;

Azure Partner has two Sale Order. This orders confirmed, but not invoiced;

SO1234=1.500 USD

SO1235=2.000 USD


I want to see this total amount (3.500 USD) in res.partner form in partner_order_total_amount field.


How can i do it?


Why i need do it?


Odoo's default credit limit calculate only invoiced amunt.

I want to calculate partner's available credit limit with not invoiced sale orders.


Thanks.

Avatar
Discard
Best Answer

Hi,

You can define a compute field inheriting the res.partner model with the following function,

class ResPartner(models.Model):
    _inherit = 'res.partner'

partner_order_total_amount = fields.Float(
string='Total Uninvoiced Sales Orders',
compute='_compute_order_total',
store=True
)

@api.depends('sale_order_ids.amount_total', 'sale_order_ids.invoice_status')
def _compute_order_total(self):
for partner in self:
total_amount = 0.0
for order in partner.sale_order_ids:
if order.invoice_status != 'invoiced' and order.state == 'sale':
total_amount += order.amount_total
partner.partner_order_total_amount = total_amount

Thanks

Avatar
Discard
Author

Dear Sachin,
Thank you very much. It is perfect and working.

Related Posts Replies Views Activity
1
Sep 23
2669
2
Sep 23
12889
1
Oct 23
1472
2
Mar 15
3785
1
May 25
912