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
[ADD] module 'stock_picking_invoice_product_group' #100
[ADD] module 'stock_picking_invoice_product_group' #100
Conversation
6e69fab
to
70d033b
Compare
059ddcf
to
28bba72
Compare
|
||
related_picking_ids = fields.Many2many( | ||
comodel_name='stock.picking', | ||
relation='account_invoice_stock_picking_rel', |
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.
v8 don't need relation, column1, column2
params
You can use
related_picking_ids = fields.Many2many('stock.picking', string='Related Pickings'
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.
@moylop260 thanks for your review.
Yes I know, the official documentation says:
The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!
but It is not entirely clear to me how table and columns names are generated so that I can use them in post_init_hook.
Any insight would be very useful and highly appreciated.
Thanks.
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.
@tafaRU
I got it
Thank you
3719c12
to
f551049
Compare
👍 |
@pedrobaeza, I would appreciate it if you could review this PR. |
Invoices created from picking grouped by product | ||
================================================ | ||
|
||
This module allows you to group invoices generated from picking by product |
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.
s/picking/pickings
6039bff
to
7e28fb5
Compare
cc93b41
to
e6e7d78
Compare
bf1933d
to
7452ebc
Compare
Travis build errors are related to #185 |
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.
This module seems to work without any trouble and implements a very useful functionality.
In the code review, though, I'd like to suggest some lesser improvements.
|
||
@api.multi | ||
def create_invoice(self): | ||
if self.group_type: |
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.
This method implements the api.multi decorator, which makes theoretically possible to have more than one record in self (also if I understand that in a transient model this is very unlikely to happen). If this happens, the syntax self.group_type will surely raise an error.
I think that a better way to write this is either change the decorator from 'api.multi' to 'api.one' or to use the 'self.ensure_one()' method in order to be sure that self always contain just one record, or to manually iterate the use of this module into the recordset using a syntax like 'for record in self'.
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.
Fixed, thanks!
categ = product.categ_id | ||
if group_type == 'group_by_product': | ||
key = (partner.id, product.id) | ||
else: |
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.
Here, in the else statement, is basically developed an implicit "default" for the field group_type: if group_type has not the value 'group_by_product', then the system should suppose that it has the value 'group_by_product_category'. This is actually not correct (the field is not declared as required, therefore it could already assume the None value) and not safe in the perspective of further developments.
I think that a better way to achieve the same result could be to explicitly set a default for the field 'group_type' and to declare it as required (either on the model definition or on the view definition).
In any case, I believe it's better to use an elif branch in order to handle the 'group_by_product_category' case, reserving the else statement to eventually handle any unexpected value.
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.
I'd prefer to leave the possibility to choose 'Group by partner' option, this is the reason for that kind of implementation.
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.
Of course, I'm not suggesting to prevent the user from choosing an option instead of the other. I'm just suggesting to handle the two different cases ('group_by_product' and 'group_by_product_category') in an if/elif statement rather than in an if/else statement. Something like:
if group_type == 'group_by_product':
key = (partner.id, product.id)
elif group_type == 'group_by_product_category':
key = (partner.id, categ.id)
else:
#Some kind of exception raising/handling
That's because an else statement in this case would implicitly define a default: let's assume the user doesn't select any group type in the wizard (which is currently possible, being the field not required), the system would behave exactly like if he selected the option 'group_by_product_category', regardless if he really did it or not.
If this is the desired behavior, it would be better to explicitly define that option as a default for the field. Moreover, I believe that the system should force the user to choose an option.
7452ebc
to
3730349
Compare
…ouping options; Added missing dependency; Updated italian localization file
@espo-tony, could you please have a final review? |
@tafaRU, |
Invoices created from picking grouped by product
This module allows you to group invoices generated from picking by product or by product category.
This is possible by selecting the related option in the wizard used for creating draft invoices.
Example
Created the following pickings:
Selecting option 'Group by product category' I get the following invoices:
On the contrary if I select option 'Group by product' I get the following invoices: