Commit Graph
16 Commits
Author SHA1 Message Date
Gorash 774a3fad0e [REF] base,all: Update modifier syntax: view migration
Apply of the migration script to update all view modifiers.

Part-of: odoo/odoo#104741
2023-08-18 09:49:13 +02:00
Arnaud Joset 2d238a9981 [IMP] sale_margin: allows putting fields before the margin in order forms
Before this commit, the margin in the sale_total group was following the total.
It was preventing putton another field before the margin. This commit allows putting
another field before the margin without depending on the installation order.

closes odoo/odoo#116820

Taskid: 3232957
X-original-commit: 03286dffa8693edce846c064795e8a26d5b61890
Related: odoo/enterprise#38886
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Signed-off-by: Arnaud Joset <arj@odoo.com>
2023-03-29 23:37:03 +02:00
Denis Ledoux 0501bbd62e [IMP] base: uniform "groups" in back-end view
This revision is to make uniform the behavior of the `groups` attribute
on the Python model fields
and on the node in the view architecture.
In both cases, remove the node from the view completely.

Before this revision,

in a back-end view:
 - In the Python model, if a field has the `groups` attribute set
   and the user is not part of
   the groups, the field is removed, completely, from the view.
 - In the view architecture, if a node has the `groups` attribute set
   and the user is not part of
   the groups, the node is made invisible (not completely removed, just
   made invisible).

in a front-end view:
 - if a node has a "groups" or "t-groups" set and the user
   is not part of the groups, the node is removed from the view.

So it's 2/3 cases removing nodes restricted to a group.
and 1/3 case making invisible nodes restricted to a group.
It's simpler to have a uniform behavior for the 3 cases,
simpler to understandard for developers.

In addition, this will help for the goal to cache back-end views.
It makes possible to convert views using the `groups_id` field
by moving the content of these views directly
in the view to which they add content which is suppose to be completely
removed when the user has not the according group.
By getting rid of the `groups_id` many2many field on `ir.ui.view`,
it makes possible to cache the view architecture without
requiring to use the groups in the cache key.
Currently, if we want to cache the view architecture,
it would be required to use the intersection of the user
groups with the `groups_id` groups of the view,
making it costly to compute the cache key,
therefore altering the performance point to cache the view
architectures.

closes odoo/odoo#95729

Related: odoo/enterprise#29592
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2022-08-19 19:10:39 +02:00
william-andre d8d47f9ff8 [REF] accounting v16. Yeeeeaah
TLDR:
* invoices are implemented using computed methods instead of onchange
* the synchronization only happens when switching tabs in the Form view
  to improve perfs.

_______________________________________________________________________

The whole engine of the synchronization of Invoices to the Journal
Entries has been refactored
* by using computed fields instead of onchange functions
* by synchronizing only from invoice to journal entry in `create` and
  `write`
* by saving when switching tabs on the Invoice form, to synchronize
  before showing the values

This comes with numerous advantages:
* no need to call the onchange methods manually
* no need to use the Form emulator to build invoices (i.e. EDI, OCR,
  intercompany, ...)
* the performance for invoices with many lines improves drastically, going
  from 2 minutes to 4 seconds to create an invoice with 500 lines
* the model is more declarative, we can now see how the values are computed
  instead of having the values being copied from various places.
* remove the hack in `onchange` that disabled the recursivity of it,
  which was unexpected and needed to be managed manually in all the
  onchange methods

This means that:
* Some fields need to be exclusively computed on journal entries values
  or invoice values, more specifically the Tax Summary widget.
  It is now
    - computed from entry lines, when opening the view
    - computed from invoice lines when changing those, because the tax lines
      will need to be recomputed anyways, erasing previously set values
    - set with an inverse function when saving; after the sync has been done
* Some possible operations previously possible have been dropped.
  (i.e. look at the removed test test_in_invoice_line_onchange_accounting_fields_1)
  This is because such a behavior was undefined (how is changing the balance going
  to affect the unit price? How is the amount currency going to affect it?)

_______________________________________________________________________

Implementation Details
----------------------

The "dynamic lines", meaning the payment terms and the tax lines are now
only created in the `create` and `write` functions.
In order to reduce code duplication, it has been implemented using
context managers used in both `account.move` and `account.move.line`
These context managers help comparing the values before/after, acting
like a local `onchange`, but getting benefit from the dirty flags from
the `compute` dependences.
This is relying on computed fields on the move (`needed_terms`) and on
the lines (`compute_all_tax`) which contain the values needed for the
related move.
Depending on the needed values and the existing values (`term_key` and
`tax_key`, respectively) the context manager will determine what needs
to be created/updated/deleted.

Some related changes are to produce a `dict` instead of a `str` for the
`tax_totals` (previously `tax_totals_json`) fields, by simplicity to
reduce the complexity of IO, and simplicity of debugging, because the
logic of the field needed to change (cannot be computed at the same time
anymore since it needed the lines to be synced)

By simplicity, and also because it makes more sense, some boolean fields
have been merged into `display_type`:
* `is_rounding_line`
* `exclude_from_invoice_tab`
* `is_anglo_saxon_line`

The `price_unit`, `quantity` and other "invoice fields" are now not set
anymore on lines that are not product lines since it didn't make any
sense to have it.

Performances
------------

You have to keep in mind that a simple `create` didn't compute a lot of
fields, for instance not taxes were set, no payment terms,...
Now it does.

```python
import random
from timeit import timeit
from odoo import Command
domain = [('company_id', 'in', (False, self.env.company.id))]
products = self.env['product.product'].search(domain).ids
partners = self.env['res.partner'].search(domain).ids
taxes = self.env['account.tax'].search(domain).ids
def create(nmove, nline):
    self.env['account.move'].create([
        {
            'move_type': 'out_invoice',
            'partner_id': random.choice(partners),
            'invoice_line_ids': [
                Command.create({
                    'name': f'line{i}',
                    'product_id': random.choice(products),
                    'tax_ids': [Command.set([random.choice(taxes)])],
                })
                for i in range(nline)
            ]
        }
        for j in range(nmove)
    ])
                                                             # After  | Before
print(timeit("create(1, 1)", globals=globals(), number=1))   # 0.11   | 0.09
print(timeit("create(100, 1)", globals=globals(), number=1)) # 2.76   | 2.50
print(timeit("create(500, 1)", globals=globals(), number=1)) # 14.56  | 12.34
print(timeit("create(1, 100)", globals=globals(), number=1)) # 1.03   | 5.52
print(timeit("create(1, 500)", globals=globals(), number=1)) # 3.99   | 125.02
print(timeit("create(50, 50)", globals=globals(), number=1)) # 19.44  | 79.55
```

Another metric that can be used is running the test suite with
`--test-tags=/account` (only `account` installed)
* before: 404s, 267127 queries (366 tests)
* after: 318s, 232125 queries (362 tests)

Why this commit title?
----------------------

Someone told me that this was the perfect way of naming your commits.
c04065abd8

task-2711317

closes odoo/odoo#96134

Related: odoo/upgrade#3715
Related: odoo/enterprise#29758
Signed-off-by: Laurent Smet <las@odoo.com>
2022-08-03 13:44:49 +02:00
Victor Feyens b1eacc842c [FIX] sale_margin: conflicting view ids
Finetuning of #85774
Fixes #86174

closes odoo/odoo#86260

X-original-commit: 6fff9ac8b4f86469c11e404442f928c2b6616e2b
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2022-03-11 13:30:48 +00:00
Achraf (abz) f7cfb820b3 [FIX] sale_margin: Correct computation of margin in groupby
For now the sale margin is incorrectly computed in group by

opw-2767397

closes odoo/odoo#86016

X-original-commit: 9c2915ad9bd5bf1d6eacf8f3a4e14bcd1d4af9f7
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Signed-off-by: Achraf <abz@odoo.com>
2022-03-08 13:58:50 +00:00
Victor Feyens becf288435 [IMP] sale_margin: clean module
* Split python file by classes
* Remove empty ir.model.access.csv file
* Correct name for views file
* Use setUpClass instead of setUp to avoid multiple setups during tests

Part-of: odoo/odoo#85001
2022-02-25 11:40:18 +00:00
oco-odoo d9a3b938fe [IMP] account, sale, purchase, l10n_latam, l10n_ar: add the possibility to use subtotals above tax groups when displaying them
A new field on tax groups makes it now possible for this group to be displayed under a subtotal label. If not set, this defaults instead to "Untaxed Amount", keeping the traditional behavior. This is intended for withholding taxes, which can now be implemented with negative taxes and a tax group with this field set.

To do that, this commit entirely refactors the way amount_by_group worked, and replaces it with a more complete json field called tax_totals_json. It also streamlines the way taxe totals are displayed on invoices, PO and SO and makes it so that a common code is called instead of copy-pasting the same block 3 times as before.

[IMP] purchase: always display tax totals by groups on purchases orders

Before, tax totals on purchase.order's form were not shown by group, and were instead all aggregated in a single "Taxes" category. The same went for the pdf export. The portal view, though, did show the totals by group. We now display the tax groups in the same way all the time.

closes odoo/odoo#74138

Task: 2457374
Related: odoo/enterprise#19802
Related: odoo/upgrade#2670
Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
2021-09-02 14:15:13 +00:00
nie 8f6815857f [FIX] sale_margin: confusing margin percentage in pivot
Steps to reproduce the bug:
- Activate Margins in Sales > Settings
- Go to the pivot view of quotations
- In Measures, click Margin (%)

Bug:
Margin percentages are aggregated by computing the sum of the margin sub-percentages instead of using the data of the aggregated row (i.e. agg. margin / agg. total).

Explanation:
This is one of the flaws of the pivot view. The best way to solve this would be to create a custom aggregation in PostgreSQL.
This commit is just hiding the measure for now.

opw:2349896

closes odoo/odoo#60354

X-original-commit: 1e3fc6894b13d51a3f6327653afbf8d5a316a21d
Signed-off-by: backspac <backspac@users.noreply.github.com>
2020-10-20 10:18:57 +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
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
Mohammed Shekha ed924e956d [IMP] various: set some fields as optional to simplify the views
This commit removes some groups that are now useless since their
only purpose was to allow the user to hide or show some fields
depending on its value, but those fields are optional now.

Task-1902765

closes odoo/odoo#31944

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2019-06-04 07:04:51 +00:00
Pragnesh Mistry 1b8050a30a [IMP] sale: Move the Margin field below Total on a sales order
move margin field from the bottom left corner of sales order to below the total_amount field
2017-05-17 16:52:09 +02:00
Goffin Simon a8e1595a12 [FIX] sale: visible cost price in sale order line
The Cost of the product(purchase_price) must be shown in the wizard opened
when changing a SO line.

opw:690180
2016-10-12 14:13:33 +02: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