[18.0][ADD]contract_invoice_suspended - #1494
Conversation
a383014 to
36ac1ab
Compare
qgroulard
left a comment
There was a problem hiding this comment.
Hi, thanks for this contribution !
It would be nice to provide a bit more context 🙂
| ========================== | ||
| Contract Invoice Suspended | ||
| ========================== | ||
|
|
||
| This module provides functionality to suspend automatic invoicing for | ||
| contracts with configurable reasons and tracking. |
There was a problem hiding this comment.
Please follow oca guidelines: https://www.odoo-community.org/readme-structure
Could you please also elaborate? What's the point of this module? How to configure it? etc.
Try to think of this module as if it was completely unknown to you, what would you like to know about it?
There was a problem hiding this comment.
is it okay like this ?
There was a problem hiding this comment.
Not quite, please see the documentation: https://www.odoo-community.org/readme-structure
There are dedicated fragments for "Usage" and "Configure", they should not be sub-section of the "Description" fragment.
There was a problem hiding this comment.
refactored this , is this okay now ?
| # OCA | ||
| "contract_line_successor", | ||
| # OCA/contract | ||
| "contract_sale", |
There was a problem hiding this comment.
Why are these two separated?
| <field | ||
| name="domain_force" | ||
| >['|', ('company_id','=',False), ('company_id','parent_of',company_ids)]</field> | ||
| </record> |
There was a problem hiding this comment.
The new convention for multi-company rule is:
[('company_id', 'in', company_ids + [False])]
| @api.depends("parent_id.suspended_reason_category_id") | ||
| def _compute_suspended_reason_category_id(self): | ||
| self.env.cr.execute( | ||
| """ | ||
| WITH RECURSIVE trid(id, parent_id, | ||
| suspended_reason_category_id, final) AS ( | ||
| SELECT | ||
| id, parent_id, id, | ||
| (parent_id IS NULL) as final | ||
| FROM contract_automatic_invoice_suspension_reason | ||
| WHERE id = ANY(%s) | ||
| UNION | ||
| SELECT | ||
| trid.id, ctr.parent_id, ctr.id, | ||
| (ctr.parent_id IS NULL) as final | ||
| FROM contract_automatic_invoice_suspension_reason ctr | ||
| JOIN trid ON (trid.parent_id = ctr.id) | ||
| WHERE NOT trid.final | ||
| ) | ||
| SELECT trid.id, trid.suspended_reason_category_id | ||
| FROM trid | ||
| WHERE final AND id = ANY(%s); | ||
| """, | ||
| [self.ids, self.ids], | ||
| ) | ||
|
|
||
| d = dict(self.env.cr.fetchall()) | ||
| for suspension_reason in self: | ||
| fetched = d.get(suspension_reason.id) | ||
| if fetched is not None: | ||
| suspension_reason.suspended_reason_category_id = fetched | ||
| elif not suspension_reason.parent_id: | ||
| suspension_reason.suspended_reason_category_id = suspension_reason | ||
| else: | ||
| suspension_reason.suspended_reason_category_id = ( | ||
| suspension_reason.parent_id.suspended_reason_category_id | ||
| ) |
There was a problem hiding this comment.
This looks super complicated to me.
Why can't we do something like:
| @api.depends("parent_id.suspended_reason_category_id") | |
| def _compute_suspended_reason_category_id(self): | |
| self.env.cr.execute( | |
| """ | |
| WITH RECURSIVE trid(id, parent_id, | |
| suspended_reason_category_id, final) AS ( | |
| SELECT | |
| id, parent_id, id, | |
| (parent_id IS NULL) as final | |
| FROM contract_automatic_invoice_suspension_reason | |
| WHERE id = ANY(%s) | |
| UNION | |
| SELECT | |
| trid.id, ctr.parent_id, ctr.id, | |
| (ctr.parent_id IS NULL) as final | |
| FROM contract_automatic_invoice_suspension_reason ctr | |
| JOIN trid ON (trid.parent_id = ctr.id) | |
| WHERE NOT trid.final | |
| ) | |
| SELECT trid.id, trid.suspended_reason_category_id | |
| FROM trid | |
| WHERE final AND id = ANY(%s); | |
| """, | |
| [self.ids, self.ids], | |
| ) | |
| d = dict(self.env.cr.fetchall()) | |
| for suspension_reason in self: | |
| fetched = d.get(suspension_reason.id) | |
| if fetched is not None: | |
| suspension_reason.suspended_reason_category_id = fetched | |
| elif not suspension_reason.parent_id: | |
| suspension_reason.suspended_reason_category_id = suspension_reason | |
| else: | |
| suspension_reason.suspended_reason_category_id = ( | |
| suspension_reason.parent_id.suspended_reason_category_id | |
| ) | |
| @api.depends("parent_id.suspended_reason_category_id") | |
| def _compute_suspended_reason_category_id(self): | |
| for suspension_reason in self: | |
| suspension_reason.suspended_reason_category_id = ( | |
| suspension_reason.parent_id.suspended_reason_category_id | |
| or suspension_reason | |
| ) |
There was a problem hiding this comment.
yes , refactored
There was a problem hiding this comment.
This was a genuine question. Are you 100% sure this is correct and efficient?
There was a problem hiding this comment.
i tested it works fine also if i understood well the functionality also this test is paasing fine ,test_compute_suspended_reason_category_id
704d3d9 to
990f45d
Compare
990f45d to
d7170cf
Compare
No description provided.