Skip to Content
मेन्यू
This question has been flagged
2 Replies
2042 Views

Hi, I have a boolean field in account.journal , and I have this function in account.payment:

@api.onchange('payment_type')
def _onchange_payment_type(self):
if not self.
invoice_ids:
# Set default partner type for the payment type
​if self.
payment_type == 'inbound':
​self.
partner_type = 'customer'
# Set payment method domain
​res = self._onchange_journal()
​if not
res.get('domain', {}):
​res['domain'] = {}
​res['domain']['journal_id'] = self.payment_type == 'inbound' and ​[('at_least_one_inbound', '=', True)] or []
​res['domain']['journal_id'].append(('type', 'in', ('bank', 'cash')))
​if self.
invoice_ids:
​res['domain']['journal_id'].append(('ap_ar', '=', True))
​return
res


What this function does is that if I activate the boolean that is in account.journal in any of the journals (in this case for banks and cash), those journals will be hidden when registering a payment in customer invoices... but for some reason it is also applied when registering a payment in vendor invoices, when I only want the function to be applied to customer invoices...

What can I do so that the function does not apply to both customers and suppliers and that it only applies to customer invoices?

Odoo 10, thank you.

Avatar
Discard
Best Answer

to modify the _onchange_payment_type function in Odoo 10 so that it only applies to customer invoices and not vendor invoices, you can make the following changes:

@api.onchange('payment_type')
def _onchange_payment_type(self):
if not self.invoice_ids:
# Set default partner type for the payment type
if self.payment_type == 'inbound':
self.partner_type = 'customer'
# Set payment method domain
res = self._onchange_journal()
if not res.get('domain', {}):
res['domain'] = {}
res['domain']['journal_id'] = [('type', 'in', ('bank', 'cash'))]
if self.invoice_ids:
res['domain']['journal_id'].append(('ap_ar', '=', True))
else:
# Reset journal domain for outbound payments (vendor invoices)
res = self._onchange_journal()
if not res.get('domain', {}):
res['domain'] = {}
res['domain']['journal_id'] = [('type', 'in', ('bank', 'cash'))]
return res


In the modified code, we introduce an else block after setting the default partner type for inbound payments. Inside the else block, we reset the journal domain by calling _onchange_journal() and assign a new domain that includes only the journals with type "bank" or "cash". This ensures that the journal domain is not modified for outbound payments (vendor invoices).

By making this change, the function will only apply the specific logic for customer invoices when the payment type is set to "inbound". For vendor invoices, the function will perform the default behavior without modifying the journal domain.


Avatar
Discard
Author

Hello, thanks for answering, apparently it doesn't work since I put the lines of code that are after the else and even so it continues to take the condition in both customer invoices and supplier invoices, here is my code:
@api.onchange('payment_type')
def _onchange_payment_type(self):
if not self.invoice_ids:
# Set default partner type for the payment type
if self.payment_type == 'inbound':
self.partner_type = 'customer'
# Set payment method domain
res = self._onchange_journal()
if not res.get('domain', {}):
res['domain'] = {}
res['domain']['journal_id'] = [('type', 'in', ('bank', 'cash'))]
if self.invoice_ids:
res['domain']['journal_id'].append(('ap_ar', '=', True))
else:
# Reset journal domain for outbound payments (vendor invoices)
res = self._onchange_journal()
if not res.get('domain', {}):
res['domain'] = {}
res['domain']['journal_id'] = [('type', 'in', ('bank', 'cash'))]
return res
It is supposed that only the journals should be hidden in customer invoices, all the journals should appear in supplier invoices, but it doesn't work.
Thank you!

try this way:
@api.onchange('payment_type')
def onchange_payment_type(self):
if not self.invoice_ids:
# Set default partner type for the payment type
if self.payment_type == 'inbound':
self.partner_type = 'customer'
# Set payment method domain
domain = [('type', 'in', ('bank', 'cash'))]
if self.invoice_ids:
domain.append(('ap_ar', '=', True))
return {'domain': {'journal_id': domain}}
return {}

In this code, we directly return the domain in the onchange_payment_type method based on the condition for customer invoices. If the payment type is 'inbound' (customer invoice), we set the domain to only include journals with types 'bank' or 'cash' and optionally with the 'ap_ar' field set to True. If the condition is not met, we return an empty dictionary to indicate no changes to the domain.

By using this approach, the function should apply the specific logic for customer invoices and not modify the journal domain for vendor invoices.

Author

It didn't work either, as it was missing to give the final touch to the if, the only thing I did in the if was to add that the type of payment was 'inbound' so that it could apply the domain, and that's how it already worked.... I don't know if it was OK, I show you my code:

@api.onchange('payment_type')
def _onchange_payment_type(self):
​if not self.invoice_ids:
​# Set default partner type for the payment type
​ ​if self.payment_type == 'inbound':
​ ​ ​self.partner_type = 'customer'
​# Set payment method domain
​domain = [('type', 'in', ('bank', 'cash'))]
​ ​if self.invoice_ids and self.payment_type == 'inbound':
​ ​ ​domain.append(('ap_ar', '=', True))
​ ​return {'domain': {'journal_id': domain}}
​ ​return {}

In this way it does work, since when I activate the boolean in any of the journals, it shows me in the customer invoices only the journals that have the checkbox activated, and in the supplier invoices this filter no longer applies to me, now it only applies to me the filter that shows me all the newspapers that are in the bank and cash.

Thank you!

Author

It's solved, thanks for your help!

Author Best Answer

It didn't work either, as it was missing to give the final touch to the if, the only thing I did in the if was to add that the type of payment was 'inbound' so that it could apply the domain, and that's how it already worked.... I don't know if it was OK, I show you my code:

@api.onchange('payment_type')
def _onchange_payment_type(self):
​if not self.invoice_ids:
​# Set default partner type for the payment type
​if self.payment_type == 'inbound':
​self.partner_type = 'customer'
​# Set payment method domain
​domain = [('type', 'in', ('bank', 'cash'))]
​if self.invoice_ids and self.payment_type == 'inbound':
​domain.append(('ap_ar', '=', True))
​return {'domain': {'journal_id': domain}}
​return {}

In this way it does work, since when I activate the boolean in any of the journals, it shows me in the customer invoices only the journals that have the checkbox activated, and in the supplier invoices this filter no longer applies to me, now it only applies to me the filter that shows me all the newspapers that are in the bank and cash.

Thank you!

Avatar
Discard
Related Posts Replies Views Activity
1
मई 17
8762
2
जून 22
2733
4
अप्रैल 20
9058
3
दिस॰ 19
9296
1
नव॰ 19
3945