[16.0][ADD] hr_personal_equipment_request_sign_oca: Show S/N in PPE Request Report#137
[16.0][ADD] hr_personal_equipment_request_sign_oca: Show S/N in PPE Request Report#137quirino95 wants to merge 2 commits into
Conversation
HekkiMelody
left a comment
There was a problem hiding this comment.
Code review, just a minor comment, otherwise LGTM
| @api.model | ||
| def _default_show_sn_report(self): | ||
| return bool( | ||
| self.env["ir.config_parameter"] | ||
| .sudo() | ||
| .get_param("hr_personal_equipment_request_sign_oca.show_sn_report", False) | ||
| ) |
There was a problem hiding this comment.
suggestion: instead of doing this configuration for the entire installation, we could do this per company. What do you think?
| # flake8: noqa: B950 | ||
| cls.template = cls.env.ref( | ||
| "hr_personal_equipment_request_sign_oca.sign_oca_template_personal_equipment_request_demo" | ||
| ) |
There was a problem hiding this comment.
suggestion (non-blocking): you can avoid disabling flake with the comment by splitting the string on two lines
cls.template = cls.env.ref(
"hr_personal_equipment_request_sign_oca."
"sign_oca_template_personal_equipment_request_demo"
)c869182 to
fc41970
Compare
| readonly=False, | ||
| ) | ||
|
|
||
| show_sn_report = fields.Boolean( |
There was a problem hiding this comment.
chore: sorry to nitpick, but settings and company have A LOT of fields from every possible module, so it's good practice to "namespace" the fields by using appropriately specific names. The likelihood of another entirely unrelated module adding a field with this name in the setting is relatively high.
Maybe ppe_report_show_sn?
There was a problem hiding this comment.
Don't worry, you're absolutely right. Yes, ppe_report_show_sn is good for me too, so I've updated code.
fc41970 to
846b073
Compare
|
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
|
@OCA/human-resources-maintainers Hello, we've been using this in prod for months. Could you take a look? We can forward port after the merge. Thanks! |
846b073 to
3fb2f82
Compare
3fb2f82 to
40ded60
Compare
|
Depends on #156 which resolves precommit issue seen |
| "depends": ["sign_oca", "hr_personal_equipment_request", "hr_employee_ppe"], | ||
| "depends": [ | ||
| "sign_oca", | ||
| "hr_personal_equipment_request", | ||
| "hr_employee_ppe", | ||
| "hr_personal_equipment_stock", | ||
| ], |
There was a problem hiding this comment.
suggestion: If/when #127 is merged, I would avoid adding a new dependency on a merged module because it might break existing installations that do not have the new dependency available.
Please consider adding a bridge module or including this dependency from the beginning, since #127 isn't merged yet.
| ) | ||
| pdf = report._render_qweb_pdf(report.report_name, [self.id])[0] | ||
| request_dict.update({"data": base64.b64encode(pdf)}) | ||
| request_dict.update({"data": self._get_pdf_report()}) |
There was a problem hiding this comment.
issue: The PDF report should be generated from the single PPE request in the loop.
| request_dict.update({"data": self._get_pdf_report()}) | |
| request_dict.update({"data": item._get_pdf_report()}) |
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| res = super().create(vals_list) | ||
| res._generate_sign_oca_request() | ||
| return res | ||
| def check_sign_oca_request(self): | ||
| if all(line.state in ["valid", "cancelled"] for line in self.line_ids) and any( | ||
| line.state == "valid" for line in self.line_ids | ||
| ): | ||
| self._generate_sign_oca_request() |
There was a problem hiding this comment.
issue: If we aren't managing serial numbers, this sign request should still be generated upon record creation: instead of removing the create override, please add a check on ppe_report_show_sn if the flow should be different.
If we really want to modify the original flow, this change should go in the commit where such flow is added.
| _inherit = "stock.picking" | ||
|
|
||
| def _action_done(self): | ||
| is_return = any(x.origin_returned_move_id for x in self.move_ids) |
There was a problem hiding this comment.
issue: _action_done can be called on multiple pickings: some of them can be returns and others maybe are not.
The problem is that is_return is True if at least one of them is a return: please identify which picking is a return and which isn't instead.
| return res | ||
|
|
||
| def action_cancel(self): | ||
| is_return = any(x.origin_returned_move_id for x in self.move_ids) |
There was a problem hiding this comment.
issue: action_cancel can be called on multiple pickings: some of them can be return and others maybe are not.
The problem is that is_return is True if at least one of them is a return: please identify which picking is a return and which isn't instead.
| def action_cancel(self): | ||
| is_return = any(x.origin_returned_move_id for x in self.move_ids) | ||
| res = super().action_cancel() | ||
| if self.equipment_request_id and not is_return: | ||
| self.equipment_request_id.check_sign_oca_request() |
There was a problem hiding this comment.
question: Why should we generate a sign request when a picking is cancelled?
| t-if="line.is_ppe" | ||
| t-if="line.is_ppe and line.state == 'valid'" |
There was a problem hiding this comment.
question: Why is this needed only when serial numbers are added? Maybe this goes in the 1st commit?
| {"name": "Employee Test 2", "user_id": cls.user_2.id} | ||
| ) | ||
|
|
||
| cls.location_employee = cls.env["stock.location"].create( |
There was a problem hiding this comment.
suggestion: This setup is the same as https://github.com/OCA/hr/blob/a2251a13108632bdd9c0c5ad3cb9e1ca60f3116f/hr_personal_equipment_stock/tests/test_hr_personal_equipment_stock.py#L15, please consider adding a common tests setup over there and reusing it here.
| cls.company_id = cls.env.company | ||
| cls.template = cls.env.ref( | ||
| "hr_personal_equipment_request_sign_oca.sign_oca_template_personal_equipment_request_demo" | ||
| "hr_personal_equipment_request_sign_oca." | ||
| "sign_oca_template_personal_equipment_request_demo" | ||
| ) | ||
| cls.company = cls.env.company | ||
| cls.company.personal_equipment_request_sign_oca_template_id = cls.template | ||
| cls.warehouse = cls.env.ref("stock.warehouse0") |
There was a problem hiding this comment.
chore: Most of these changes do not belong here, please move them to the previous commit where this piece of code has been added.
| readonly=False, | ||
| ) | ||
|
|
||
| ppe_report_show_sn = fields.Boolean( |
There was a problem hiding this comment.
suggestion: Please add some documentation for the new behavior, for example: this new flag might be added in the CONFIGURATION fragment.
Depends on #127
Added possibility to show Serial Numbers in PPEs request report file. A related setting is present (default is
False).This also means that Sign request cannot be created on Personal Equipment Request Acceptance, but now it's done only when related pickings are completed.
Furthermore, now in report only "Valid" lines are visible, since showing cancelled lines doesn't make sense.