-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[16.0][MIG] sale_fixed_discount: Migration to 16.0 #2614
[16.0][MIG] sale_fixed_discount: Migration to 16.0 #2614
Conversation
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": ["sale", "account_invoice_fixed_discount"], |
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.
Hi, this migration is linked to another pull request, you should make a link to this request by adding it in the requirement.txt file. You can take a look at this documentation https://github.com/OCA/maintainer-tools/wiki/Use-temporary-reference%28s%29-to-another-pull-request%28s%29 to have more information about the procedure
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.
@FrancoMaxime Thanks for the feedback. Didn't know about the test-requirements.txt
. Appreciated and added the requirement. I'm first going to fix up the dependency module though prior to completing this one. Going to mark it as WIP.
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.
@PieterPaulussen You're welcome :)
6115186
to
711e764
Compare
/ocabot migration sale_fixed_discount |
test-requirements.txt
Outdated
@@ -1 +1,2 @@ | |||
odoo_test_helper | |||
odoo-addon-sale_fixed_discount @ git+https://github.com/OCA/account-invoicing.git@refs/pull/1488/head#subdirectory=setup/sale_fixed_discount |
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.
odoo-addon-sale_fixed_discount @ git+https://github.com/OCA/account-invoicing.git@refs/pull/1488/head#subdirectory=setup/sale_fixed_discount | |
odoo-addon-account-invoice-fixed-discount @ git+https://github.com/OCA/account-invoicing.git@refs/pull/1488/head#subdirectory=setup/account_invoice_fixed_discount |
@PieterPaulussen This line is intended to install the module that is not yet merged. So, account_invoice_fixed_discount.
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.
@PieterPaulussen you still need to adapt the module name at the end of the string. I think you only changed the beginning.
Good work so far.. looking forward to do the testing/review.
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've refactored the flow of this module to align it with the new implementation of account_invoice_fixed_discount
and the option arises to remove the requirement of the module entirely as both features can be used as stand-alone. The only problem is that the discount_fixed
value does not get updated when invoicing the order.
Perhaps you know of a better way like an optional dependency or a new module entirely?
f6e0ae6
to
027b356
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.
There is a bug when creating the new SO with discount. First the fixed discount is removed, but when saving the form, it is not correct.
video (9).webm
test-requirements.txt
Outdated
@@ -1 +1,2 @@ | |||
odoo_test_helper | |||
odoo-addon-sale_fixed_discount @ git+https://github.com/OCA/account-invoicing.git@refs/pull/1488/head#subdirectory=setup/sale_fixed_discount |
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.
@PieterPaulussen you still need to adapt the module name at the end of the string. I think you only changed the beginning.
Good work so far.. looking forward to do the testing/review.
@api.constrains("discount_fixed", "discount") | ||
def _check_discounts(self): | ||
"""Check that the fixed discount and the discount percentage are consistent.""" | ||
for line in self: | ||
if line.discount_fixed and line.discount: | ||
currency = line.currency_id | ||
calculated_fixed_discount = float_round( | ||
line._get_discount_from_fixed_discount(), | ||
precision_rounding=currency.rounding, | ||
) | ||
|
||
@api.onchange("discount_fixed") | ||
if calculated_fixed_discount != line.discount: | ||
raise ValidationError( | ||
_( | ||
"The fixed discount %(fixed)s does not match the calculated " | ||
"discount %(discount)s %%. Please correct one of the discounts." | ||
) | ||
% { | ||
"fixed": line.discount_fixed, | ||
"discount": line.discount, | ||
} | ||
) |
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 v15, only discount or discount_fixed was allowed. In the calculation they where implemented additive (even though you could not enter both, and also the further tax calculation wouldn't work properly.)
In v16 they are treated as one and will be both be set. This leads also to a different visualization in the PDF documents, because now both (fixed and %) is added to the PDF:
I think the change is not perfect because of the PDF output.
I am not sure if we should allow fixed + % in future, when we get the tax calculation to handle this correctly. In the v15 tax calculation this wasn't easy to implement, but with the v16 changes this might be possible.
But when we allow both, we need to decide if we use:
price = (unit_price - fixed) * discount
or
price = (unit_price * discount) - fixed
I prefer the first one.
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.
@CRogos Actually, I personally disagree. The fixed discount should only serve as a convenience implementation. All actual discounts are applied through the discount
field. This also greatly simplifies the modules code.
So the workflow will always be price = unit_price * discount
and nothing more.
I don't see the added benefit of splitting those.
I agree that the discount might be misleading on the PDF though. Perhaps we should not add a separate column for this and just do something like:
$ 100.00 (10.0%)
Or the other way around. We could add the currency to it as clarification?
The initial bug you mentioned in your video also needs to be addressed. I'll follow up on the issue this Friday.
Thanks for testing!
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.
@PieterPaulussen I also had a quick view in the new tax calculation and you are right that even in the new implementation we should not change price = unit_price * discount
. I like your proposal regarding the PDF $100.00 (10%)
.
I have one more issue, when we use discount_fixed and discount as synonym. When you enter the discount_fixed, the discount is updated. But when you enter a discount, the dicount_fixed field stays on 0.00.
Shouldn't we make dicount_fixed as computed column which directly updates discount?
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.
@CRogos I've added some additional changes to the module. Particularly one to stabilise the rounding differences for the calculated subtotals.
As for your specific issue where saving the sale order, I believe it is affected on the test environment by a different module also available in the sale-workflow repo. I've checked it locally and was unable to reproduce the error.
/ocabot migration sale_fixed_discount |
86a812f
to
27b9a26
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.
@PieterPaulussen are you still working on this?
I've installed the code from your branch, and I ran into several errors.
Either it is not working or I did something wrong.
</th> | ||
</xpath> | ||
<xpath | ||
expr="//section[@id='details']//tbody[hasclass('sale_tbody')]//t[@t-foreach='lines_to_report']/tr//t[@t-if='not line.display_type']//td[3]/div" |
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 get the following error when I install the module from your branch.
Traceback (most recent call last):
File "/src/odoo/odoo/http.py", line 1584, in _serve_db
return service_model.retrying(self._serve_ir_http, self.env)
File "/src/odoo/odoo/service/model.py", line 133, in retrying
result = func()
File "/src/odoo/odoo/http.py", line 1611, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "/src/odoo/odoo/http.py", line 1815, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "/src/odoo/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
result = endpoint(**request.params)
File "/src/odoo/odoo/http.py", line 697, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/dataset.py", line 46, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/src/odoo/odoo/api.py", line 461, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/src/odoo/odoo/api.py", line 448, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "<decorator-gen-74>", line 2, in button_immediate_install
File "/src/odoo/odoo/addons/base/models/ir_module.py", line 74, in check_and_log
return method(self, *args, **kwargs)
File "/src/odoo/odoo/addons/base/models/ir_module.py", line 456, in button_immediate_install
return self._button_immediate_function(type(self).button_install)
File "/src/odoo/odoo/addons/base/models/ir_module.py", line 580, in _button_immediate_function
registry = modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "<decorator-gen-14>", line 2, in new
File "/src/odoo/odoo/tools/func.py", line 87, in locked
return func(inst, *args, **kwargs)
File "/src/odoo/odoo/modules/registry.py", line 90, in new
odoo.modules.load_modules(registry, force_demo, status, update_module)
File "/src/odoo/odoo/modules/loading.py", line 488, in load_modules
processed_modules += load_marked_modules(cr, graph,
File "/src/odoo/odoo/modules/loading.py", line 372, in load_marked_modules
loaded, processed = load_module_graph(
File "/src/odoo/odoo/modules/loading.py", line 231, in load_module_graph
load_data(cr, idref, mode, kind='data', package=package)
File "/src/odoo/odoo/modules/loading.py", line 71, in load_data
tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind)
File "/src/odoo/odoo/tools/convert.py", line 763, in convert_file
convert_xml_import(cr, module, fp, idref, mode, noupdate)
File "/src/odoo/odoo/tools/convert.py", line 829, in convert_xml_import
obj.parse(doc.getroot())
File "/src/odoo/odoo/tools/convert.py", line 749, in parse
self._tag_root(de)
File "/src/odoo/odoo/tools/convert.py", line 709, in _tag_root
raise ParseError(msg) from None # Restart with "--log-handler odoo.tools.convert:DEBUG" for complete traceback
odoo.tools.convert.ParseError: while parsing None:7
Error while validating view:
Element '<xpath expr="//section[@id='details']//table/tbody//t[@t-foreach='sale_order.order_line']/tr//t[@t-if='not line.display_type']//td[3]/div">' cannot be located in parent view
View error context:
{'file': '/src/user/modules/oca/sale-workflow/sale_fixed_discount/views/sale_portal_templates.xml',
'line': 2,
'name': 'sale_order_portal_content_fixed_discount',
'view': ir.ui.view(870,),
'view.model': False,
'view.parent': ir.ui.view(861,),
'xmlid': 'sale_order_portal_content_fixed_discount'}
can't we change it to:
<xpath
expr="//div[@t-field='line.price_unit']"
position="replace"
>
<div
t-if="line.discount >= 0 or line.fixed_discount >= 0"
t-field="line.price_unit"
t-att-style="(line.discount or line.discount_fixed) and 'text-decoration: line-through' or None"
t-att-class="((line.discount or line.discount_fixed) and 'text-danger' or '') + ' text-right'"
/>
<div t-if="line.discount_fixed">
<t
t-esc="line.price_unit - line.discount_fixed"
t-options='{"widget": "float", "decimal_precision": "Product Price"}'
/>
</div>
</xpath>
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's a warning from pylint-odoo when you use replace
. I specifically had to refactor this in order to not get the warning.
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 wasn't happy using replace either. Something which should be avoided so modules do not overwrite each other. But I did not have a good idea in this case.
To bypass this warning you can set a priority="100" in the template node.
I'll have a look on your solution.
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.
Please disregard my previous comment. My assumption was wrong. I did however test the module again and did not come across your installation errors.
I ran it on a new demo database and only installed sale_fixed_discount
and manually added sale_management
. Nothing more.
Are you experiencing a side effect from another module in your installation?
</div> | ||
</xpath> | ||
<xpath | ||
expr="//section[@id='details']//table/tbody//t[@t-foreach='lines_to_report']/tr//t[@t-if='not line.display_type']//td[@t-if='display_discount']" |
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 also get here an error and replaced it with:
expr="//section[@id='details']//t[@t-if='not line.display_type']//td[@t-if='display_discount']"
I was unable to reproduce the issue. Are you experiencing a side effect from another module in your installation? |
27b9a26
to
f4ee788
Compare
@CRogos I've run into an issue with the framework. Adding onchanges to both |
f4ee788
to
7230972
Compare
@PieterPaulussen are you still working on this? On my last test, setting the fixed discount to a value and than resetting it to 0 wasn't working. |
c4b1d4c
to
77aac31
Compare
instead of `sale.group_discount_per_so_line`
The sale order view in the portal was not displaying the fixed discount.
b211163
to
548b852
Compare
Rebased and updated with new pre-commit changes |
@pedrobaeza can you merge this PR? |
I let @rousseldenis to give their blessing |
@rousseldenis will you add some feedback on this PR? |
@pedrobaeza I don't think there will be further feedback... can we continue without @rousseldenis ? |
/ocabot merge nobump |
What a great day to merge this nice PR. Let's do it! |
Congratulations, your PR was merged at 35a8436. Thanks a lot for contributing to OCA. ❤️ |
No description provided.