Skip to content
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

Merged

Conversation

Trivedi-Vacha-SerpentCS
Copy link

@Trivedi-Vacha-SerpentCS Trivedi-Vacha-SerpentCS commented Jun 25, 2018

[MIG][11.0]hr_contract_multi_jobs: Migrated module in 11.0

@pedrobaeza pedrobaeza added this to the 11.0 milestone Jun 25, 2018
@pedrobaeza pedrobaeza mentioned this pull request Jun 25, 2018
71 tasks
@Trivedi-Vacha-SerpentCS Trivedi-Vacha-SerpentCS changed the title 11.0 hr contract multi jobs [Mig][11.0]hr_contract_multi_jobs: Migrated module in 11.0 Jun 28, 2018
@Trivedi-Vacha-SerpentCS Trivedi-Vacha-SerpentCS changed the title [Mig][11.0]hr_contract_multi_jobs: Migrated module in 11.0 [Mig][11.0]hr_contract_multi_jobs: Migration to 11.0 Jun 28, 2018
@Trivedi-Vacha-SerpentCS Trivedi-Vacha-SerpentCS force-pushed the 11.0-hr_contract_multi_jobs branch 2 times, most recently from 639267b to 006ce52 Compare July 3, 2018 05:43
@Trivedi-Vacha-SerpentCS Trivedi-Vacha-SerpentCS changed the title [Mig][11.0]hr_contract_multi_jobs: Migration to 11.0 [MIG][11.0]hr_contract_multi_jobs: Migration to 11.0 Jul 3, 2018
sambarros pushed a commit to sambarros/hr that referenced this pull request Jul 26, 2018
Copy link
Member

@nikul-serpentcs nikul-serpentcs left a 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(
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as here

Copy link
Member

@nikul-serpentcs nikul-serpentcs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review LGTM

@Trivedi-Vacha-SerpentCS
Copy link
Author

@pedrobaeza Commit squshed, Ready to merge

Copy link
Contributor

@espo-tony espo-tony left a 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
Copy link
Contributor

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.

Copy link
Member

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',
Copy link
Contributor

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',
Copy link
Contributor

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',
Copy link
Contributor

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',
Copy link
Contributor

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"/>
Copy link
Contributor

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>

@pedrobaeza
Copy link
Member

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'
)
Copy link
Contributor

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

@Trivedi-Vacha-SerpentCS
Copy link
Author

@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
Copy link
Contributor

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 means if main_job is always True;
  • We are also sure there is exactly 1 main_job, therefore main_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)

Copy link
Member

@nikul-serpentcs nikul-serpentcs Oct 1, 2018

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.

Copy link
Contributor

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?

Copy link
Contributor

@espo-tony espo-tony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review LGTM

@nikul-serpentcs
Copy link
Member

@pedrobaeza if it's Done then Move Forward

@pedrobaeza pedrobaeza merged commit 536c6dc into OCA:11.0 Oct 2, 2018
@Trivedi-Vacha-SerpentCS Trivedi-Vacha-SerpentCS deleted the 11.0-hr_contract_multi_jobs branch September 4, 2020 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants