Commit Graph
49 Commits
Author SHA1 Message Date
Yannick Tivisse 232d66069a [IMP] sale: Make some field precomputed 2021-12-02 12:12:03 +01:00
Thibault Libioulle 8bbbc69e40 [IMP] sale{,_project}_margin: improve service product cost computation
Prior to this commit, the cost of a service product was computed based
on its standard_price.

With this commit, the product cost is computed based on the timesheet
amounts linked to the sale order, if the sale order has a delivering
method of type timesheet.

PR : #70527
See odoo/upgrade#2616

task-2458135
2021-09-03 12:45:58 +02:00
Andrea Grazioso (agr-odoo) 830a28b6ad [FIX] sale_margin: avoid purchase price reset on order confirm
- Create a service product with cost 0
- Create a sales quotation
- Add the service product, change the cost to a positive quantity
- Save and Confirm.

Purchase Price (cost) will be reset to 0

opw-2481564

closes odoo/odoo#70036

X-original-commit: 8a8ff03f6111f377bcd9c2b0f584c450b82a4182
Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
2021-04-28 14:50:22 +00:00
Victor Feyens 8a48aee8eb [FIX] sale_margin: purchase_price performance.
When installing sale_margin, the computed fields will be computed on existing
sale.order and sale.order.line in database.  On huge databases, the computation
may take a lot of time, depending on the configuration (multi-company, multi-currency, ...)

The current commit improves the computation of the purchase_price
(recently changed to a computed field), by avoiding unnecessary currency
conversions when possible (one less query to get the conversion rates).

In a multi-currency database where the products have no cost defined
(standard_price field), the sale_margin installation takes up to 50% less time.

closes odoo/odoo#52338

X-original-commit: 3c9841d1aa4fc5b10012c8239a31d6e7f8676fc0
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-06-03 10:36:18 +00:00
Thomas Dieuzeide 72087777ac [FIX] sale_margin: compute fields performance at install
Installing sale_margin module on a db with a lot of sale.order was impossible.

This commit significantly improves performances.
Went from many hours (forecasted) to 15 minutes on a db with 300k orders

For sale.order:
  - Duplicating logic between edit mode and non edit mode
  - Edit mode logic stays the same as before
  - Non edit mode uses read_group to speed up the computation

X-original-commit: 9f1ea7427cdb6984f175f5111e4c9a4c5f013af2
2020-06-03 10:36:17 +00:00
Victor Feyens d585882e2f [FIX] sale_margin: keep old Margin label
And use "Margin (%)" for the recently added margin_percent field
computing the margin in % and not in money.

closes odoo/odoo#43130

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-01-14 13:29:10 +00:00
Victor Feyens aca2b71919 [FIX] sale_margin: cost computation on empty line
Onchanges can be triggered after computes and therefore, we could have a line with an uom
but without product, leading to a conversion from "no uom" to the order line uom, which isn't
accepted.

closes odoo/odoo#42691

X-original-commit: 1bc9963cfc19a4bc5896a647423f81274936db00
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-01-03 12:55:07 +00:00
Jinal Patel 6ae2ba8d84 [ADD] sale_margin: margin percentage
New field to express the profitability percentage of a Sales Order (/SO line).

task-2033253

closes odoo/odoo#39926

Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
2019-12-23 14:15:56 +00:00
Victor Feyens 1bcc175e37 [FIX] sale_margin: no uom on line.
Since the purchase_price is now computed, it may be triggered before an
uom is set on the product line (onchanges may happen after computes).

closes odoo/odoo#41808

X-original-commit: 9ebbdd24752a0ff1c1057fc533074555810ffa39
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2019-12-12 13:57:08 +00:00
Victor Feyens b9fabffe4e [IMP] sale_margin: make the cost a computed field.
And clean the code mess.

closes odoo/odoo#40953

Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
2019-11-29 12:09:40 +00:00
Victor Feyens 0b8eb71d71 [FIX] sale_margin: recompute purchase_price on product_id_change.
When creating sale order lines from the matrix (sale_product_matrix),
the purchase_price weren't computed

No cleaner change has been found to ensure the cost is computed.

Triggering all onchanges from the server side is quite tricky and dirty
to do...

closes odoo/odoo#40986

X-original-commit: 5c15b1310729129e390b455b0d1e0ac367f8dd69
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2019-11-14 09:55:14 +00:00
Naglis Jonaitis 0fe2b4530f [IMP] *: remove digits attribute from Monetary fields
* account, hr_contract, hr_expense, point_of_sale, sale_margin,
website_sale_delivery, website_sale_wishlist

digits only works on Float fields, on Monetary fields it has no
effect:

- The column_type of a monetary field is always numeric
- It is not applied in `convert_to_column()` or `convert_to_cache()`
- It is not part of `description_attrs`, so it will not be included in
the output of `fields_get()`

closes odoo/odoo#35336

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2019-08-02 11:17:12 +00:00
Mitali Patel 9d710df076 [REF] *: use the new decimal precision syntax
Since previous commit moved decimal_precision module's feature into base,
use the new syntax for fields declaration
Remove the imports to the removed module
Remove the module from dependency in manifest

sed -i "s|digits=dp.get_precision('\([A-Z a-z]*\)')|digits='\1'|" **.py
sed -i "/from odoo.tools import decimal_precision as dp/d" **py
2019-07-03 11:16:24 +00:00
Christophe Simonis 5e81b18e24 [MERGE] forward port branch saas-12.3 up to 0247d2f35f 2019-06-27 20:45:52 +02:00
Christophe Simonis 465909f0fd [MERGE] forward port branch 12.0 up to cd21c016b0 2019-06-27 18:01:07 +02:00
Nicolas Martinelli 34644baab0 [FIX] sale_margin: no company
Complement of commit 7a24df4889

opw-2009044

closes odoo/odoo#34374

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
2019-06-26 09:33:37 +00:00
Yannick Tivisse f5dfe4727c [IMP] api.py: Rename company_id/company_ids into company/companies
The goal is to be coherent with the user property.

Actually, company_id and company_ids on the environment are no fields.

Calling env.company_id returns a browse record, not an id.
2019-05-29 08:09:15 +00:00
Yannick Tivisse a5b6f31cf2 [IMP] base: Contextualize the multi company
Purpose
=======

Allow the user to select the allowed companies for which he wants to see records
on top of selecting his current company.

It is confusing for users to see the records from the company he is connected to
and the records of the children companies.

Instead of using the hierarchy of companies to access records across companies,
the user can now select (from his set of allowed companies) the companies for
which he wants to access records.

/!\ This means that the user will interact with records from company A when in
company B.
Example: a SO has been created and confirmed in A. When in B, I create the
invoice from it.

Specifications
==============

1/ Deprecate the parent/children hierarchy on the res.company model. The fields are
kept on the res.company model to ensure the retro-compatibility, but won't be used
accross the standard code anymore. The only functional usage for this mechanism
was to allow to see records from several companies by creating a virtual parent
company, which will be possible with the new mechanism.

2/ By default, a user will only see the records of the company he is connected
to (or records without a company). (It is still editable by the user if needed).
For that, put this information in the user context, to allow having different
configurations on different browser tabs. Instead of having domains like
['|',
('company_id', '=', False),
('company_id', 'child_of', user.company_id.id)]
you'll have something like
['|',
('company_id', '=', False),
('company_id', 'in', company_ids)]
Note that the 'company_ids' is a value that is passed in the evaluation
context on the record rule, as we already have user, or time.
company_ids is a list of the ids of all the enabled companies in the
user's context.

3/ Out of the generic improvements brought by this task, this will illustrate
issues that could exist since several versions. For example, it should not be
possible to create a scrap order for the company A with a package of the company
B, or it should not be possible to create an invoice on the company A with
payment terms from the company B. Before the version 12.0, it was easy to
encounter this kind of issues as the admin was the SUPERUSER_ID. A positive side
effect of the fact that the SUPERUSER_ID has become an inactive user was to
make it more difficult to introduce mismatch on the records, but haven't solved
the issue, as it was still possible to do it with parent companies
configuration. Some of these issues have been fixed in this commit, but all the
business flows should be re-tested to check if an ir.rule should be introduced
(eg: a multi company rule for stock.quand.package), if the company of a record
is correctly transfered to another record created from the first record (eg:
From a SO, create an invoice and a payment, the company of the sales order
should be transfered on the invoice and the payment, even if the company of the
sales order is A and I'm logged into the company B with the company A enabled.

4/ Currently, if I click on a button on a notification email (example 'View
Task'), I face a traceback if I'm not logged into the company of the record.
Now, if you click on a button and if you have access to the record, the correct
company will be automatically set.

5/ If I display a kanban view with several records from several companies (and
an image), all the images should be displayed.

6/ Currently if you copy paste an url, this will crash if you're not in the
correct company. This won't be fixed because it's quite impossible to do it in
a clean way. This task brings a workaround. Copy/Paste -> Traceback -> Log into
the correct company, re-copy/paste -> Ok.

7/ 2 property methods have been added on the environment to retrieve the company
on which the user is logged in and the companies the user enabled, on a specific
tab.
That way, when creating a record, instead of doing
default=lambda self: self.env.user.company_id
do
default=lambda self: self.env.company_id
On the other hand, to retrieve the enabled companies, do
companies = self.env.company_ids

8/ Modify the Company Switcher widget to allow to log into another company
WITHOUT writing on the res.users (and thus bringing cache invalidation issues
and so on). Also allow to enable several companies and see records from several
companies, and independantly of the other browser's tabs.

9/ When focusing on a tab, save the current company configuration on the local
storage. That way, when doing 'CTRL+T' or a middle click, the context is
propagated to the new tab.

10/ Improve the error message in case of multi company access errors. Now, when
the user is in debug mode, display the related names of the records and the name
of the user who brings the issue.

11/ Remove the context erasing when writing on a res.users
This is probably coming from the migration to new API of the base module.
The context was not propagated at this moment, which was a common mistake at
that time. When migrating the module, probably by using the 'black box' method,
as the context was not propagated, it was erased on the new version. This is
now an issue because the context (i.e. the enabled companies) was erased when
writing on a res.users, leading to tracebacks.
See: https://github.com/odoo/odoo/commit/7eab8e26d3d46c53f4be924d6a34e80a66e74960#diff-4c2e738ee8f64f11806c889ea097b5e7R624

12/ Fix the crash manager on redirect warnings. The issue is the following
- Create an invoice on a company without a configured CoA.
- Set a partner
- On the onchange_partner_id, a redirect warning is raised to propose you
to configure a CoA
- Click on 'Go to the configuration panel'
- A generic warning says something like 'Do you want to discard your changes?'
- Click on yes, the page refreshes, but not on the redirect action.
Now, set correctly the action on the hash, and reload instead. The breadcrumb is
lost for example, but you reach the correct action at least.

13/ Introduce a res.group to enable/disable the multi company per tab
feature.

14/ To help the users to know which tab is in which company, add the
possibility to have a favicon per company. When creating a company,
the classical 'O' icon is colored by default in a random color.

15/ Remove the company switcher on the frontend. This was mainly there
to allow a user to swicth to the company linked to the website.
This behavior is now transparent to the user. If the website A is
activated, then the company set on the context is the company of the
website.

16/ Deprecated the _company_default_get method on the res.company
model. Remove the method _get_company on the res.users model.

17/ Add 'allowed_company_ids' and 'current_company_id' on the pyeval
context. You can now use those variables on domains in the views to
access directly to the activated company.ies on the current tab.

TaskID: 1960971

closes odoo/odoo#32341

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2019-05-13 08:57:49 +00:00
Christophe Simonis 0e7675847f [MERGE] forward port branch saas-12.1 up to 0f4abc5c22 2019-02-22 16:25:02 +01:00
Jorge Pinna Puissant d132870cab [FIX] sale_margin: product margin round error
In a SO without customer:

Before this commit, the _product_margin wasn't working. This because,
as the customer is not defined, the pricelist isn't defined either,
and therefore currency of the pricelist is also undefined.
When you call the round function, in an undefined currency
an error is raised.

Now we take into account if customer is defined.

closes odoo/odoo#30675
2019-02-13 08:24:41 +00:00
Nans Lefebvre 3b256ba487 [FIX] sale_margin: make sale.order.line create override handle section lines
The sale.order.line model has a 'display_type' field since 762adedece
that specify if the line is a dummy line used for presentation purposes.
These dummy lines are 'section' lines or 'note' lines.
If it is the case, the line does not have a product_id.
The sale_margin module overrides the create method of lines to add the margin
computation, assuming there are no dummy lines since that part of the code
is older than the new feature.
As a result the line creation would crash on a key error on dummy lines.

We now skip the margin computation if the line has a display_type.

opw 1939881

closes odoo/odoo#31035
2019-02-13 08:24:59 +00:00
Christophe Simonis 4b8bd36219 [MERGE] forward port branch saas-11.3 up to bab2a191d2 2018-11-16 15:39:02 +01:00
Christophe Simonis 15f686eef6 [MERGE] forward port branch 11.0 up to 468dab6748 2018-11-15 20:39:10 +01:00
Christophe Simonis 468dab6748 [MERGE] forward port branch saas-15 up to 3c78026dc0 2018-11-15 18:57:09 +01:00
Josse Colpaert 0b586677e2 [FIX] sale_margin: Error in Margin calculation
If cost(purchase_price) was 0, margin calculation was incorrect.
The function _product_margin didn't consider the use case
where the cost of the product was set to 0 on the line.

So before the fix it fallback on standard price instead of considering  a cost of 0.

opw:1890452, 1885587
2018-11-08 13:10:10 +01:00
Yannick Tivisse 7a24df4889 [FIX] sale_margin: Fall back on the user company if not set on the SO line
As the company is not required on a sales order, this could lead to
errors when trying to compute the margin as _convert is expecting
a valid company.
2018-04-17 13:56:39 +02:00
Yannick Tivisse 7a282c9965 [IMP] *: Replace all occurences of 'compute' by '_convert' 2018-04-13 16:54:28 +02:00
XavierDo 2966d4faed [IMP] product: rename product.uom into uom.uom
Also rename product.uom.categ into uom.category to
 give it a decent name.
2018-02-26 14:27:26 +01:00
Christophe Simonis e90cd4aa73 [MERGE] forward port branch saas-16 up to 1581d31b3e 2017-07-11 16:28:36 +02:00
Christophe Simonis 1581d31b3e [MERGE] forward port branch saas-15 up to 0f2a06e29b 2017-07-11 16:06:17 +02:00
Christophe Simonis 0ac49ee1e4 [MERGE] forward port branch saas-11 up to d52f0a29b4 2017-07-11 10:45:36 +02:00
Christophe Simonis d52f0a29b4 [MERGE] forward port branch 9.0 up to 479facb783 2017-07-11 10:34:07 +02:00
Christophe Simonis dd43071638 [MERGE] forward port branch saas-16 up to 278e478d55 2017-06-27 14:19:31 +02:00
Christophe Simonis 34b432d528 [MERGE] forward port branch saas-15 up to 4d79a1ff58 2017-06-26 19:19:39 +02:00
Christophe Matthieu 6a0e07b6aa [FIX] sale_margin: wrong margin when update the discount 2017-06-22 10:25:49 +02:00
Christophe Simonis ed2ddeccdf [MERGE] forward port branch saas-16 up to 1b50c829ef 2017-06-15 18:46:47 +02:00
Christophe Simonis 1b50c829ef [MERGE] forward port branch saas-15 up to 9713dc2e1f 2017-06-15 18:44:16 +02:00
Martin Trigaux b144e09a10 [FIX] sale_margin: apply same logic than sale override
If some required fields are not present in the created values, they are computed
based on the onchange.
This was introduced at 5c4765130 to allow to import sale order lines without
specifying uom.

If sale_margin is installed, the same issue will occure as it assumes there is
a value for product_uom

Add test, courtesy of Mourad Elhadj Mimoune, Akretion

Closes #17613
2017-06-15 15:43:36 +02:00
Xavier Morel b897dcde15 [FIX] P3: import pattern which doesn't seem to work right
``import odoo.addons.foo as bar`` doesn't seem to properly trigger the
import hook in Python 3 (it blows up on decimal_precision and
base). Thus convert *all* examples of that pattern to the more
sensible ``from odoo.addons import foo as bar``.
2017-05-22 13:30:50 +02:00
xmo-odoo b4429c2a91 [FIX] Various P3-related import changes
* LDAP import: python-ldap is not python3-compatible, pyldap is

  Warning: only supported from debian Stretch (current testing)?
  https://packages.debian.org/search?searchon=names&keywords=pyldap

* implicitly relative imports
* imports of moved or removed stdlib modules

issue #8530
2017-04-28 09:06:53 +02:00
Denis Ledoux cf98d58f88 [FIX] *: fix product.uom._compute_price method calls
During the conversion to the new api,
the method `product.uom`.`_compute_price` has had its signature
changed.

Formerly, it was:
`def _compute_price(self, cr, uid, from_uom_id, price, to_uom_id=False):`
Now, it is:
`def _compute_price(self, price, to_unit):`

Basically:
- the first argument `from_uom_id` is removed, and you now should
call this method from the model record directly
- the last argument is no longer a kwargs

Some calls to this method were still done the former way:
 - Some have been added during forward ports
 - Some are oversights when this method has been converted to the new api

This revision corrects the calls that were still done the former way
to the new way.

opw-694871
2016-11-24 11:33:38 +01:00
Christophe Simonis ea675d8b76 [MERGE] forward port branch saas-12 up to ff7f3d6 2016-11-18 18:03:47 +01:00
Christophe Simonis 4e7eda8b85 [MERGE] forward port branch 9.0 up to 95abb22 2016-11-18 16:46:53 +01:00
Thibault Delavallée f3d6a54e36 [REF] product_uom, *: clean price computation method
product_uom._compute_price() is now an ensure_one multi methods, taking
a browse record as second unit. This helps simplifying and unifying the
various calls and price computation methods.
2016-08-01 15:05:32 +02:00
Christophe Simonis a3bc09ce94 [FIX] base,sale_margin: correct error introduced during previous forward-port 2016-02-29 13:09:06 +01:00
Christophe Simonis 1c7f5a45e5 [MERGE] forward port of branch saas-7 up to d016457 2016-02-29 12:30:27 +01:00
Martin Trigaux f5cfe04398 [MERFE] Forward port of branch saas-8 up to e4bf03aeaf 2015-12-21 13:32:55 +01:00
Anand Kansagra 1ca86e70de [IMP] sale_margin: Migrate into new api. 2015-12-16 10:29:03 +01:00
Anand Kansagra 332aded356 [MOV] sale_margin: Re-organised file structure. 2015-12-16 10:28:14 +01:00