Function python for odoo 10
up vote
-2
down vote
favorite
I have a function for filling in many fields automatically with an api.onchange() decorator.
@api.onchange('nursery_morning', 'nursery_evening', 'responsible_partner')
def retrieve_responsible_nursery(self):
if self.nursery_morning or self.nursery_evening:
if self.responsible_partner:
if not self.resp_civility1 and not self.resp_name1 and not self.resp_cp1 and not self.resp_num1
and not self.resp_address1 and not self.resp_town1
and not self.resp_phone1 and not self.resp_phonemobile1:
self.resp_civility1 = self.responsible_partner.title.name
self.resp_name1 = self.responsible_partner.name
self.resp_cp1 = self.responsible_partner.zip_id.name
self.resp_num1 = self.responsible_partner.street_number_id.name
self.resp_address1 = self.responsible_partner.street_id.name
self.resp_town1 = self.responsible_partner.city_id.name
self.resp_phone1 = self.responsible_partner.phone
self.resp_phonemobile1 = self.responsible_partner.mobile
This function works, but I do not want the fields to change until the fields are saved in the database and not before.
Currently, the fields do not change once one of the fields listed are filled but not saved in database
python odoo
add a comment |
up vote
-2
down vote
favorite
I have a function for filling in many fields automatically with an api.onchange() decorator.
@api.onchange('nursery_morning', 'nursery_evening', 'responsible_partner')
def retrieve_responsible_nursery(self):
if self.nursery_morning or self.nursery_evening:
if self.responsible_partner:
if not self.resp_civility1 and not self.resp_name1 and not self.resp_cp1 and not self.resp_num1
and not self.resp_address1 and not self.resp_town1
and not self.resp_phone1 and not self.resp_phonemobile1:
self.resp_civility1 = self.responsible_partner.title.name
self.resp_name1 = self.responsible_partner.name
self.resp_cp1 = self.responsible_partner.zip_id.name
self.resp_num1 = self.responsible_partner.street_number_id.name
self.resp_address1 = self.responsible_partner.street_id.name
self.resp_town1 = self.responsible_partner.city_id.name
self.resp_phone1 = self.responsible_partner.phone
self.resp_phonemobile1 = self.responsible_partner.mobile
This function works, but I do not want the fields to change until the fields are saved in the database and not before.
Currently, the fields do not change once one of the fields listed are filled but not saved in database
python odoo
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I have a function for filling in many fields automatically with an api.onchange() decorator.
@api.onchange('nursery_morning', 'nursery_evening', 'responsible_partner')
def retrieve_responsible_nursery(self):
if self.nursery_morning or self.nursery_evening:
if self.responsible_partner:
if not self.resp_civility1 and not self.resp_name1 and not self.resp_cp1 and not self.resp_num1
and not self.resp_address1 and not self.resp_town1
and not self.resp_phone1 and not self.resp_phonemobile1:
self.resp_civility1 = self.responsible_partner.title.name
self.resp_name1 = self.responsible_partner.name
self.resp_cp1 = self.responsible_partner.zip_id.name
self.resp_num1 = self.responsible_partner.street_number_id.name
self.resp_address1 = self.responsible_partner.street_id.name
self.resp_town1 = self.responsible_partner.city_id.name
self.resp_phone1 = self.responsible_partner.phone
self.resp_phonemobile1 = self.responsible_partner.mobile
This function works, but I do not want the fields to change until the fields are saved in the database and not before.
Currently, the fields do not change once one of the fields listed are filled but not saved in database
python odoo
I have a function for filling in many fields automatically with an api.onchange() decorator.
@api.onchange('nursery_morning', 'nursery_evening', 'responsible_partner')
def retrieve_responsible_nursery(self):
if self.nursery_morning or self.nursery_evening:
if self.responsible_partner:
if not self.resp_civility1 and not self.resp_name1 and not self.resp_cp1 and not self.resp_num1
and not self.resp_address1 and not self.resp_town1
and not self.resp_phone1 and not self.resp_phonemobile1:
self.resp_civility1 = self.responsible_partner.title.name
self.resp_name1 = self.responsible_partner.name
self.resp_cp1 = self.responsible_partner.zip_id.name
self.resp_num1 = self.responsible_partner.street_number_id.name
self.resp_address1 = self.responsible_partner.street_id.name
self.resp_town1 = self.responsible_partner.city_id.name
self.resp_phone1 = self.responsible_partner.phone
self.resp_phonemobile1 = self.responsible_partner.mobile
This function works, but I do not want the fields to change until the fields are saved in the database and not before.
Currently, the fields do not change once one of the fields listed are filled but not saved in database
python odoo
python odoo
edited Nov 8 at 10:21
John Murray
813514
813514
asked Nov 8 at 9:25
PseudoWithK
89
89
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Two ways you can approach this, it seems that you could change these fields to be related fields if they are only ever going to hold the values from a related record (responsible_partner).
resp_civility1 = fields.Char("Field Label", related="responsible_partner.title.name")
Editing this field will edit the linked record as well, so it will not be a good fit if you want to change this value at all, or you could set it as read-only if you don't want it to be edited from here.
Another way to do it would be to override the write method, this will write the values at the time of saving the record and would look like this:
@api.multi
def write(self, vals):
res = super(ModelName, self).write(vals)
if vals.get('nursery_morning') or vals.get('nursery_evening') or vals.get('responsible_partner'):
if res.nursery_morning or res.nursery_evening:
if res.responsible_partner:
if not res.resp_civility1 and not res.resp_name1 and not res.resp_cp1 and not res.resp_num1
and not res.resp_address1 and not res.resp_town1
and not res.resp_phone1 and not res.resp_phonemobile1:
res.resp_civility1 = res.responsible_partner.title.name
res.resp_name1 = res.responsible_partner.name
res.resp_cp1 = res.responsible_partner.zip_id.name
res.resp_num1 = res.responsible_partner.street_number_id.name
res.resp_address1 = res.responsible_partner.street_id.name
res.resp_town1 = res.responsible_partner.city_id.name
res.resp_phone1 = res.responsible_partner.phone
res.resp_phonemobile1 = res.responsible_partner.mobile
return res
This will first call the write method of the model, then it will check if the three fields are being written to, if so it will run the same logic from your onchange method. Replace ModelName with whatever you have named your model class.
Hello, your soluce don't work :/
– PseudoWithK
Nov 19 at 14:36
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Two ways you can approach this, it seems that you could change these fields to be related fields if they are only ever going to hold the values from a related record (responsible_partner).
resp_civility1 = fields.Char("Field Label", related="responsible_partner.title.name")
Editing this field will edit the linked record as well, so it will not be a good fit if you want to change this value at all, or you could set it as read-only if you don't want it to be edited from here.
Another way to do it would be to override the write method, this will write the values at the time of saving the record and would look like this:
@api.multi
def write(self, vals):
res = super(ModelName, self).write(vals)
if vals.get('nursery_morning') or vals.get('nursery_evening') or vals.get('responsible_partner'):
if res.nursery_morning or res.nursery_evening:
if res.responsible_partner:
if not res.resp_civility1 and not res.resp_name1 and not res.resp_cp1 and not res.resp_num1
and not res.resp_address1 and not res.resp_town1
and not res.resp_phone1 and not res.resp_phonemobile1:
res.resp_civility1 = res.responsible_partner.title.name
res.resp_name1 = res.responsible_partner.name
res.resp_cp1 = res.responsible_partner.zip_id.name
res.resp_num1 = res.responsible_partner.street_number_id.name
res.resp_address1 = res.responsible_partner.street_id.name
res.resp_town1 = res.responsible_partner.city_id.name
res.resp_phone1 = res.responsible_partner.phone
res.resp_phonemobile1 = res.responsible_partner.mobile
return res
This will first call the write method of the model, then it will check if the three fields are being written to, if so it will run the same logic from your onchange method. Replace ModelName with whatever you have named your model class.
Hello, your soluce don't work :/
– PseudoWithK
Nov 19 at 14:36
add a comment |
up vote
0
down vote
Two ways you can approach this, it seems that you could change these fields to be related fields if they are only ever going to hold the values from a related record (responsible_partner).
resp_civility1 = fields.Char("Field Label", related="responsible_partner.title.name")
Editing this field will edit the linked record as well, so it will not be a good fit if you want to change this value at all, or you could set it as read-only if you don't want it to be edited from here.
Another way to do it would be to override the write method, this will write the values at the time of saving the record and would look like this:
@api.multi
def write(self, vals):
res = super(ModelName, self).write(vals)
if vals.get('nursery_morning') or vals.get('nursery_evening') or vals.get('responsible_partner'):
if res.nursery_morning or res.nursery_evening:
if res.responsible_partner:
if not res.resp_civility1 and not res.resp_name1 and not res.resp_cp1 and not res.resp_num1
and not res.resp_address1 and not res.resp_town1
and not res.resp_phone1 and not res.resp_phonemobile1:
res.resp_civility1 = res.responsible_partner.title.name
res.resp_name1 = res.responsible_partner.name
res.resp_cp1 = res.responsible_partner.zip_id.name
res.resp_num1 = res.responsible_partner.street_number_id.name
res.resp_address1 = res.responsible_partner.street_id.name
res.resp_town1 = res.responsible_partner.city_id.name
res.resp_phone1 = res.responsible_partner.phone
res.resp_phonemobile1 = res.responsible_partner.mobile
return res
This will first call the write method of the model, then it will check if the three fields are being written to, if so it will run the same logic from your onchange method. Replace ModelName with whatever you have named your model class.
Hello, your soluce don't work :/
– PseudoWithK
Nov 19 at 14:36
add a comment |
up vote
0
down vote
up vote
0
down vote
Two ways you can approach this, it seems that you could change these fields to be related fields if they are only ever going to hold the values from a related record (responsible_partner).
resp_civility1 = fields.Char("Field Label", related="responsible_partner.title.name")
Editing this field will edit the linked record as well, so it will not be a good fit if you want to change this value at all, or you could set it as read-only if you don't want it to be edited from here.
Another way to do it would be to override the write method, this will write the values at the time of saving the record and would look like this:
@api.multi
def write(self, vals):
res = super(ModelName, self).write(vals)
if vals.get('nursery_morning') or vals.get('nursery_evening') or vals.get('responsible_partner'):
if res.nursery_morning or res.nursery_evening:
if res.responsible_partner:
if not res.resp_civility1 and not res.resp_name1 and not res.resp_cp1 and not res.resp_num1
and not res.resp_address1 and not res.resp_town1
and not res.resp_phone1 and not res.resp_phonemobile1:
res.resp_civility1 = res.responsible_partner.title.name
res.resp_name1 = res.responsible_partner.name
res.resp_cp1 = res.responsible_partner.zip_id.name
res.resp_num1 = res.responsible_partner.street_number_id.name
res.resp_address1 = res.responsible_partner.street_id.name
res.resp_town1 = res.responsible_partner.city_id.name
res.resp_phone1 = res.responsible_partner.phone
res.resp_phonemobile1 = res.responsible_partner.mobile
return res
This will first call the write method of the model, then it will check if the three fields are being written to, if so it will run the same logic from your onchange method. Replace ModelName with whatever you have named your model class.
Two ways you can approach this, it seems that you could change these fields to be related fields if they are only ever going to hold the values from a related record (responsible_partner).
resp_civility1 = fields.Char("Field Label", related="responsible_partner.title.name")
Editing this field will edit the linked record as well, so it will not be a good fit if you want to change this value at all, or you could set it as read-only if you don't want it to be edited from here.
Another way to do it would be to override the write method, this will write the values at the time of saving the record and would look like this:
@api.multi
def write(self, vals):
res = super(ModelName, self).write(vals)
if vals.get('nursery_morning') or vals.get('nursery_evening') or vals.get('responsible_partner'):
if res.nursery_morning or res.nursery_evening:
if res.responsible_partner:
if not res.resp_civility1 and not res.resp_name1 and not res.resp_cp1 and not res.resp_num1
and not res.resp_address1 and not res.resp_town1
and not res.resp_phone1 and not res.resp_phonemobile1:
res.resp_civility1 = res.responsible_partner.title.name
res.resp_name1 = res.responsible_partner.name
res.resp_cp1 = res.responsible_partner.zip_id.name
res.resp_num1 = res.responsible_partner.street_number_id.name
res.resp_address1 = res.responsible_partner.street_id.name
res.resp_town1 = res.responsible_partner.city_id.name
res.resp_phone1 = res.responsible_partner.phone
res.resp_phonemobile1 = res.responsible_partner.mobile
return res
This will first call the write method of the model, then it will check if the three fields are being written to, if so it will run the same logic from your onchange method. Replace ModelName with whatever you have named your model class.
answered Nov 9 at 13:28
djames
642
642
Hello, your soluce don't work :/
– PseudoWithK
Nov 19 at 14:36
add a comment |
Hello, your soluce don't work :/
– PseudoWithK
Nov 19 at 14:36
Hello, your soluce don't work :/
– PseudoWithK
Nov 19 at 14:36
Hello, your soluce don't work :/
– PseudoWithK
Nov 19 at 14:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204774%2ffunction-python-for-odoo-10%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown