-
-
Notifications
You must be signed in to change notification settings - Fork 664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MIG][11.0]hr_contract_multi_jobs: Migration to 11.0 #453
[MIG][11.0]hr_contract_multi_jobs: Migration to 11.0 #453
Conversation
639267b
to
006ce52
Compare
[BSSFL-495] Commercial Invoice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve Code
if contract.contract_job_ids: | ||
main_jobs = contract.contract_job_ids.filtered('is_main_job') | ||
if len(main_jobs) != 1: | ||
raise Warning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Trivedi-Vacha-SerpentCS Remove Warning
use userError
self.contract_id.write({'contract_job_ids': | ||
[(0, 0, {'job_id': self.job_id.id, | ||
'is_main_job': True})]}) | ||
self.assertTrue(self.contract_id.job_id.id == self.job_id.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Trivedi-Vacha-SerpentCS IMO assertTrue
replace assertEqual
.
Ex. self.assertEqual(self.contract_id.job_id.id, self.job_id.id)
'is_main_job': True}), | ||
(0, 0, {'job_id': self.job_2_id.id, | ||
'is_main_job': False})]}) | ||
self.assertTrue(self.contract_id.job_id.id == self.job_id.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as here
Fix field selection and french translation
006ce52
to
27e0a2a
Compare
27e0a2a
to
b6e7256
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review LGTM
@pedrobaeza Commit squshed, Ready to merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some lesser and cosmetic notes
""" | ||
for contract in self: | ||
main_job = contract.contract_job_ids.filtered('is_main_job' | ||
) or False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove or False
because the filtered method will return an empty recordset if no record matches the condition. An empty recordset will be evaluated as False in the following conditional statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@espo-tony Is not need to remove, because after @Trivedi-Vacha-SerpentCS check if condition
class HrContract(models.Model): | ||
_inherit = 'hr.contract' | ||
|
||
contract_job_ids = fields.One2many('hr.contract.job', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, break the line just after (
in order to get a nicer and more readable indentation
_description = 'Relational object between contract and job' | ||
|
||
name = fields.Char(string='Job', related='job_id.name', index=True) | ||
job_id = fields.Many2one('hr.job', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like earlier, please, break the line just after (
string='Job', | ||
required=True, | ||
ondelete='cascade') | ||
contract_id = fields.Many2one('hr.contract', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like earlier, please, break the line just after (
class HrJob(models.Model): | ||
_inherit = 'hr.job' | ||
|
||
contract_job_ids = fields.One2many('hr.contract.job', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like earlier, please, break the line just after (
<field name="arch" type="xml"> | ||
|
||
<field name="job_id" position="replace"> | ||
<field name="job_id" readonly="1"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, if you only wish to add a readonly attribute to this element, use XPath attributes functionality instead than remove. It should be something like:
<field name="job_id" position="attributes">
<attribute name='readonly'>1</attribute>
</field>
And we need to remove the plural on the module name. |
""" | ||
for contract in self: | ||
main_job = contract.contract_job_ids.filtered('is_main_job' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, put )
on the same line than the rest of the statement it belongs
61be847
to
07b4c0d
Compare
@pedrobaeza Module Renamed Done |
for contract in self: | ||
main_job = contract.contract_job_ids.filtered('is_main_job') | ||
if main_job: | ||
main_job = main_job[0].job_id.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the api.constraint
just below, I don't think this if
statement is required. That's because:
- We are sure there is at least 1
main_job
, which meansif main_job
is always True; - We are also sure there is exactly 1
main_job
, thereforemain_job
is a recordset containing exactly 1 record, which means its fields can be directly accessed through dot-notation (no need to use[0]
to access 1st and only element) - If you don't explicitely invoke a
write
method, you don't necessarily need to pass the ID (an integer), you can directly pass the record.
I'd rather write it as:
main_job = contract.contract_job_ids.filtered('is_main_job').job_id
contract.job_id = main_job
Or even write the same thing in a single line (if you manage to stay within the max line length)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@espo-tony Here if not get main_job
then ..?
if Your Conditions are False, so @Trivedi-Vacha-SerpentCS Used If a condition.
If Dev. Removed main_job in UT that time use our scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nikul-serpentcs I argue that the condition is never false, because in the code there is a constraint ensuring there is always 1 and only 1 main_job
. Am I wrong?
86af602
to
d85f604
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review LGTM
@pedrobaeza if it's Done then Move Forward |
[MIG][11.0]hr_contract_multi_jobs: Migrated module in 11.0