I want to get the list of the character fields from another model depending upon the matching of one field between 2 models, I wrote the code, the data is coming in the logs, but isn't getting assigned to the Selection field, can anyone help me with it?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Buchhaltung
- Lager
- PoS
- Project
- MRP
Diese Frage wurde gekennzeichnet
1
Antworten
680
Ansichten
Following is the code @Ray Carnes
account_id = fields.Many2one(
'account.account',
string='Fixed Asset Account',
help="Select the fixed asset account."
)
capacity_form = fields.Selection(
selection=[],
string='Capacity',
help="Select the capacity for the selected fixed asset account."
)
@api.onchange('account_id')
def _onchange_account_id(self):
if self.account_id:
# Fetch all capacities related to the selected account
asset_records = self.env['account.asset'].search([
('account_asset_id', '=', self.account_id.id)
])
# Prepare the selection list
capacities = [(asset.capacity, asset.capacity) for asset in asset_records if asset.capacity]
print('Capacities are', capacities)
# Dynamically update the selection options for capacity_form
self._fields['capacity_form'].selection = capacities
self.capacity_form = capacities
# Reset the value of capacity_form if it doesn't match the new options
if self.capacity_form not in dict(capacities):
self.capacity_form = False
else:
# Clear the selection if no account_id is selected
self._fields['capacity_form'].selection = []
self.capacity_form = False
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!
Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!
RegistrierenVerknüpfte Beiträge | Antworten | Ansichten | Aktivität | |
---|---|---|---|---|
|
2
Nov. 24
|
2912 | ||
Blank Page After Logged in.
Gelöst
|
|
1
Nov. 23
|
3200 | |
|
1
Sept. 23
|
4622 | ||
|
0
Apr. 21
|
3522 | ||
|
2
Juni 25
|
1791 |
Your question is very theoretical. Can you post your code or something specific? Where would readers start if they wanted to help?