-
-
Notifications
You must be signed in to change notification settings - Fork 686
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
[14.0][ADD] Module sale_stock_picking_invoicing #1025
[14.0][ADD] Module sale_stock_picking_invoicing #1025
Conversation
27e6185
to
beec094
Compare
Thanks @kittiu by your review, I'm close this PR because in my view it's important confirm with the mainteners of the repo if there are interest in include this functionality here and I think we lost the "window" to made this extraction from Brazilian Localization and will be better check this case in the future v16. |
315db4e
to
8a61a62
Compare
Reopen because as talked in #1672 the question about if this implementation would has interest outside Brazilian Localization project was answered, and to keep the isolation and modularization of stock_picking_invoicing will be better another module to integrate the functionality of create Invoice from Picking when it's linked to a Sale Order, some points about the implementation:
So for keep compatible with the Brazilian Localization I think will be better check this possibility to Grouping Sale Lines in the future in another PR or in versions v16, v17 or the newest.
The review and tests of people outside Brazilian Localization are important to know if there are any change that can make the module more compatible with another cases of use. cc @renatonlima @rvalyi @mileo @gabrielcardoso21 @marcelsavegnago @kittiu @Christian-RB |
8a61a62
to
1e1c624
Compare
About important changes made in the last two commits:
Other modules can included new fields in Sale Order and include this fields in the dict of creation Invoice from sale, for example: account_payment_sale https://github.com/OCA/bank-payment/blob/14.0/account_payment_sale/models/sale_order.py#L41 Example with demo data, account_payment_sale and sale_commission modules installed:
Case where "Sale Create Invoice Policy" defined as stock_picking Create made in Stock Picking In order to avoid errors with the tests made by CI when the enviroment are Demo the default "Sale Create Invoice Policy" defined as "Sale Order", so for test this case you need to change in Company view or Sale Settings for "Stock Picking" The commits are separated to let brazilian community check this changes in a easy way, but if necessary I can merge all commits and let only one. |
thank you for the hard work @mbcosta I promiss I'll look at that soon. If I forget please ping me again. We have to take the opportunity to modularize stock_invoice_picking indeed... |
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.
@mbcosta I would say it's a bit late for us to focus on v14 unfortunately... I mean the module is quite large and we are not going to sell any v14 project anymore for instance nor migrate customer to v14 and I think people on v14 can work their way the way it is now in the Brazilian localization...
Would it be possible to try to make the equivalent PR on v16? I know this might be some work... But honestly it has more chance to enter in v16 than v14 that is already being phased out...
This module depends on: | ||
|
||
* sale_management | ||
* stock_picking_invoicing |
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.
not the same list as in the manifest
"version": "14.0.1.0.0", | ||
"maintainers": ["mbcosta", "renatonlima"], | ||
"depends": [ | ||
"sale_management", |
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.
are you sure sale_management is required? If yes could you please just explain why? (and eventually leave a short comment why here)
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.
By some reason the sale module create menuitem with attribute active="False" https://github.com/OCA/OCB/blob/14.0/addons/sale/views/sale_views.xml#L8 and sale_management change for active="True" https://github.com/OCA/OCB/blob/14.0/addons/sale_management/views/sale_management_views.xml#L4
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 reviewed a part of the module (all except the wirzard) and I suggest a few English changes. As for the wizard I'll review later, but eventually that's cool if you could check if all the comments are still required or if some might be dropped.
Actually the module isn't that large, I'm confident we can get it merged in 14.0
result = "sale_order" | ||
return result | ||
|
||
sale_create_invoice_policy = fields.Selection( |
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.
sale_invoicing_policy would be a much better name
("sale_order", "Sale Order"), | ||
("stock_picking", "Stock Picking"), | ||
], | ||
string="Sale Create Invoice Policy", |
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.
change the variable name and drop the string
], | ||
string="Sale Create Invoice Policy", | ||
help="Define, when Product Type are not service, if Invoice" | ||
" should be create from Sale Order or Stock Picking.", |
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/be create/be created/
s/or Stock Picking/or from StockPicking/
string="Sale Create Invoice Policy", | ||
help="Define, when Product Type are not service, if Invoice" | ||
" should be create from Sale Order or Stock Picking.", | ||
default=_default_sale_create_invoice_policy, |
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.
change to default_sale_invoicing_policy
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
sale_create_invoice_policy = fields.Selection( |
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.
change to sale_invoicing_policy
# Case only Products Type 'product' | ||
raise UserError( | ||
_( | ||
"When 'Sale Create Invoice Policy' is defined as" |
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.
change to When 'Sale Invoicing Policy' is defined...
1e1c624
to
1e2bedf
Compare
Thanks @rvalyi for review, I made the changes, about the wizards it's important to check if the Refund case should not get values from "_prepare_invoice" and "_prepare_invoice_lines" of Sale module as I did, and in the _create_invoice method https://github.com/akretion/account-invoicing/blob/14.0-NEW-sale_stock_picking_invoicing/sale_stock_picking_invoicing/wizards/stock_invoice_onshipping.py#L149 I use as reference the original Sale method https://github.com/OCA/OCB/blob/14.0/addons/sale/models/sale.py#L681 to get and include the Down Payments. |
raise UserError( | ||
_( | ||
"When 'Sale Invoicing Policy' is defined as" | ||
"'Stock Picking' the Invoice only can be created" |
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/only can be/can only be/
"When 'Sale Invoicing Policy' is defined as" | ||
"'Stock Picking' the Invoice only can be created" | ||
" from Stock Picking, if necessary you can change" | ||
" this in Company or Sale Settings." |
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/from Stock Picking/from the Stock Picking/
s/change this in Company/in the Company/
lines = new_lines | ||
else: | ||
# Case only Products Type 'product' | ||
raise UserError( |
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.
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.
Thanks @mileo for review, the UserError just appear when there are only Lines with Product Type 'product' if there are any Service line the Invoice will be create, it's a way to inform the user about the "Sale Invoicing Policy" ( similar to the message when Product must be Delivered to be able Create the Invoice ), in the case of Services the 'product' must be defined as Type 'service'
Demo data has a Sale Order of the case of Product and Service, for now in this case will be create two Invoices, one with the Service created from Sale Order and the other from Picking,
Service Invoice
Try to create Invoice from Sale Order, there lines but the policy chosen are Stock Picking
Create from Stock Picking
This is the expected behavior in brazilian localization, but I think this can be analise, debate and if necessary change, for example:
- If Policy are Stock Picking create only one Invoice from Picking( get Services Lines in the same way of 'Down Payments' )
- If there are Product and Service lines ignore the "Sale Invoicing Policy" and allow Create from Sale Order
- Other ideas
1e2bedf
to
092aa34
Compare
9e5995e
to
e1528f2
Compare
e1528f2
to
9fa9973
Compare
Force-Push to remove file sale_stock_picking_invoicing/models/stock_rule.py, because it should be in stock_picking_invocing as suggest in the above Review, by this reason the CI tests fail here so this PR now depends of PR #1782 ( already with two Approves ) |
9fa9973
to
4fefe3a
Compare
Thanks @rvalyi with rebase the PR back to be green, I took a time to check the PR again to be sure everything work as well with Extract PR of l10n_br_sale_stock |
|
||
def _get_partner_to_invoice(self): | ||
partner_id = super()._get_partner_to_invoice() | ||
partner = self.env["res.partner"].browse(partner_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.
you can avoid this browse here if you compare partner_id with self.sale_id.partner_invoice_id.id directly 2 lines below in if partner != self.sale_id.partner_invoice_id:
(partner_invoice_id is required so no need to check it's not False/None)
4fefe3a
to
d536bbe
Compare
partner_id = super()._get_partner_to_invoice() | ||
if self.sale_id: | ||
if partner_id != self.sale_id.partner_invoice_id.id: | ||
partner_id = self.sale_id.partner_invoice_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.
in fact, you can simplify further to just:
if self.sale_id:
partner_id = self.sale_id.partner_invoice_id.id
if it's the same it will affect partner_id but it won't hurt performance and the code will be simpler
or eventually something like:
partner_id = self.sale_id.partner_invoice_id.id if self.sale_id else super()._get_partner_to_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.
Done, the error in the tests is the problem we saw yesterday the Tests of module account_invoice_pricelist fail at a specific Date Time
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.
OK, the PR seems OK now. I will wait a few hours, trigger the tests again and approve once everything is green again. Thank you for the awesome work and sorry for the delay. Would be great if you could port it to 16.0 as well... (you can skip v15)
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 didn't saw your comment and just make a force push, I have tried to find where is the problem but not success, the clue is the problem related with Date Time, after UTC midnight the tests back to work
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.
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.
Ok, perfect
d536bbe
to
065bfb8
Compare
065bfb8
to
5fca51a
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.
OK for me.
Thanks @rvalyi for your review, no problems for delay, this was important to make a better 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.
LGTM
This PR has the |
and finally... /ocabot merge nobump |
Hey, thanks for contributing! Proceeding to merge this for you. |
Congratulations, your PR was merged at 7aeee74. Thanks a lot for contributing to OCA. ❤️ |
Module sale_stock_picking_invoicing, based in https://github.com/OCA/l10n-brazil/tree/12.0/l10n_br_sale_stock , depends #1014.
This module extends Stock Picking Invoicing implementation to Sale, you can define the Sale Creation Invoice Policy, if the invoice should create from Sale Order or Stock Picking, in this case, the information used at invoice come from Sale Order e.g.: Price Unit, Payment Terms, and others fields. Similar feature exist in v8 core.
Implementation questions when "Sale Creation Invoice Policy" is "Stock Picking" :
When Products of Sale Order has lines where "Product Type" is "Storable Product" the button "Create Invoice" in Sale Order become invisible even when Product "Invoice Policy" defined as "Ordered quantities", is this right? Or it should be possible create invoice from Sale Order in this case? My undestand for now is as "Sale Creation Invoice Policy" is general rule should be has priority over the "Invoice Policy" defined in each Product.
There are two similar buttons to create invoice from Sale Order, one just appear in status Sale the other appear in all status but will be open with Down Payments option selected. Should be keep the second button to allow Down Paymens?
In the case of Sale Order has lines with Product Type "Storable Product" and "Service" will be create two separated Invoices, one created from Sale Order an other from Stock Picking, should be try to join and create only one? Or it should be a Parameter in the system?
As said this module is based in l10n_br_sale_stock, by this reason I like to ask if the License Header and the CONTRIBUTORS.MD should be keeped as the same based files?
It is possible reference mutiple sale lines in only one invoice line https://github.com/odoo/odoo/blob/14.0/addons/sale/models/account_move.py#L34, but there is a error when Posted Invoice:
Issue odoo/odoo#77028
PR with FIX odoo/odoo#77195
By this reason today the module not allow grouping stock moves when has sale_line_id, the PR above solve the problem, waiting merge to make useful here.
cc @renatonlima @rvalyi @mileo @gabrielcardoso21 @marcelsavegnago