Commit Graph
31 Commits
Author SHA1 Message Date
Adrien Widart c2bfba7ff2 [FIX] purchase_{stock,mrp}: compute price difference of a kit
In automated-AVCO configuration, buying a kit at a higher price than its
cost can create inconsistencies in the accounting.

To reproduce the issue:
(Need account_accountant. Use demo data)
1. Create a product category PC:
    - Costing Method: AVCO
    - Inventory Valuation: Automated
    -  Set up the Price Difference Account PDA
2. Create 3 products P_kit, P_compo01, P_compo02
    - Type: Storable
    - Category: PC
    - P_compo01:
        - Cost: 10
    - P_compo02:
        - Cost: 20
3. Create a bill of materials:
    - Product: P_kit
    - Type: Kit
    - Components:
        - 1 x P_compo01
        - 1 x P_compo02
4. On P_kit's form, "Compute Price from BoM":
    - The cost should be $30
5. Create a purchase order PO with one line:
    - Product: P_kit
    - Quantity: 1
    - Unit Price: 100
6. Confirm PO and process the receipt
7. Create and Post the bill

Error: There is an error in the journal items of the bill: the value for
PDA is $85

When posting the bill, for each account move line, the module computes
the stock valuation of the associated product and the price difference.
To do so, it sums the valuation of all related outgoing stock moves and
divides by the quantity to get the value per unit, then it compares with
the unit price used on the PO's line. Here is the issue: in case of a
kit, there is one outgoing move per component while the PO's line is
linked to the kit itself.

Therefore, in the above case, it uses the outgoing moves of P_compo01
and P_compo02, adds up their value ($10 + $20 = $30) and then divides by
the total quantity (one P_compo01 and one P_compo02, thus $30 / 2 =
$15). This is the reason why it considers that the unit value of P_kit
equals $15. Then, since the unit price on the PO's line is $100, it gets
a price difference value equal to $85.

When comparing the unit value of the kit and its unit price, the unit
value should not be divided by the quantity of components ($30 should
not be divided by 2). Moreover, when buying such a kit at $100, the
surplus ($70) should be distributed among each component. However, it is
difficult to define a rule to correctly weight this distribution.
Therefore, this surplus will be considered as a price difference.

OPW-2566546

closes odoo/odoo#82463

X-original-commit: 20888055d4271bf3cf9e7bc3d42150a1f72e4495
Signed-off-by: Arnold Moyaux <arm@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
2022-01-10 14:49:52 +00:00
JF Aubert 047f2e556f Cherry pick of 20858c2a8805d9ec08edb98b090badf6c73fc342 failed
stdout:

stderr:
13:41:03.985365 git.c:344               trace: built-in: git cherry-pick 20858c2a8805d9ec08edb98b090badf6c73fc342
error: Cherry-picking is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: cherry-pick failed
----------
status:

closes odoo/odoo#79933

Signed-off-by: William Henrotin (whe) <whe@odoo.com>
2021-11-17 15:52:19 +00:00
Touati Djamel (otd) 222d38ad01 [FIX] purchase_stock, purchase_mrp: adjust the qty of purchased kit correctly
Steps to reproduce the bug:
- Create a BOM kit for “product K”  with:
    - 2 * “product A”
    - 1 * “product B”
- Create a PO for 1 unit of “product K” > confirm
- A receipt delivery with 2 units of “product A” and 1 unit of B will be created
- Modify the ordered Qty to 2 units of “Product K”

Problem:
The receipt delivery will not be updated correctly (4 units of product A and 3 of product B)
because the `"_prepare_stock_moves"` function computed the previous quantity wrong based on the moves quantities
since the moves are for products A and B, not product F.(do not take into account the products in kit)

Solution:
For kit products, do not calculate from the `"stock.move"`, calculate the difference between the quantity before and after the change

opw-2645719

closes odoo/odoo#77838

Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
2021-10-05 14:16:58 +00:00
Rémy Voet (ryv) 974c4398b4 [REF] *mrp*: batch _bom_find
Some usage of `_bom_find` are performance bottleneck (one request by
product). By example, when the mrp is installed, search products
with fields compute by `_compute_quantities` (e.g. 'Negative forecasted
quantity'). it is due to the override of `_compute_quantities`
in mrp which will make (in the worst case) a `_bom_find` for each
product in the DB.
To avoid this situation the `_bom_find` method become batched
which can handle several products in once. The signature of the method
has changed and uniformize in all module.

Example performance Gain:
------------------------
In a DB with 7000 products (type 'product'), 500 locations, 1800 BoM,
9000 Stock moves, etc. Search in the tree view with filter "Negative
forecasted quantity":
Before: 10879 (nb SQL request) 12.67 +- 0.11 sec (Total RPC Time)
After: 159 (nb SQL request) 1.82 +- 0.03 sec (Total RPC Time)

task-2439019
2021-03-30 09:27:05 +00:00
Nicolas Martinelli 684b628c5a [FIX] purchase_mrp: receive kits with multiple UOM
- Create 3 products A, B & C
  A is in Units
  B is in kg
  C is in m
- Create a BOM kit for A using 1 kg of B and 1 m of C
- Create a PO for A, validate
- Receive the picking

An error is raised: "Conversion from Product UoM ... to Default UoM ...
is not possible as they both belong to different Category!."

It happens because `_compute_qty_received` incorrectly converts
quantities.

The computation of the quantity received for kits is done in 2 steps:
first we compute the quantity the same way we do it for a regular
product, then we overwrite the quantity with the value computed for
kits.

We can compute the quantity correctly at once by calling `super` only on
lines which are not kits.

opw-2302807

closes odoo/odoo#55047

X-original-commit: b82f71dac9452de9c1e16cde552fe260fec3c262
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
2020-07-28 12:38:33 +00:00
Martin Trigaux 400cc4f14e [FIX] *: correct all or improve code translation lookup
This commit fixes all issues detected by the new pylint
gettext-variable test.
It converts some calls to the new syntax
  _("Foo %s", bar)

to progressively migrate the code to the new syntax.

A few calls were not technically incorrect but still detected by the
linter.

  _("Foo" +
    "Bar")

has been converted to

  _("Foo"
    "Bar")

as it has the same effect and make sure the argument is of type
asteroid.Const instead of BinOp).

closes odoo/odoo#53683

Related: odoo/enterprise#11467
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-06-30 10:19:59 +00:00
Rémy Voet (ryv) 421d2d21aa [FIX] purchase_mrp: fix count MO in case of MTO
task-2241471
2020-06-15 16:59:41 +02:00
Rémy Voet (ryv) 53252608d7 [REF] mrp: backorder mechanism
Allow to "backorder" a production, meaning create another manufacturing
order with the quantity remaining to produce. We also use the
reservation of the first order on the next ones by using
`post_inventory` on the first one and moving the newly created stock
moves to the backorder.

We introduce a wizard similar to the one in stock.
Backorders have a sub-sequence.
Backorders are linked together through the procurement group.
We allow creating a backorder even if workorders are running by closing
them, the backorder will call `button_plan` and create its own.

task-2241471
2020-06-15 16:59:40 +02:00
Simon Lejeune 9d98c43581 [REF] purchase_stock: push the extra quantity
With a product configured as buy on order and a warehouse configured as
receipt in two steps, if the user increases the quantity on a po line
generated by a sale order before confirming it, the system will send all
the quantity to input but only the ordered quantity to customer. The
issue is that the "extra quantity" will stay in input.

We fix this issue by creating a new move with the extra quantity to the
input location so that push rules will send the extra quantity to stock
while the ordered quantity will be sent to the customer.

There was also an issue when incrementing the quantity on the po line
after confirmation if the po line was the result of a reordering rule:
only a move from supplier to the location of the reordering rule was
created.

This commit also introduces a change of semantic:
`created_purchase_line_id` is cleared after confirming the RFQ. This
allows to merge more in `_merge_moves`.

task-1981355

closes odoo/odoo#43545

Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
2020-01-28 14:51:36 +00:00
Rémy Voet (ryv) b0d22b5752 [IMP] purchase_mrp: link MO<->MO<->PO in case of MTO
In case of MTO (+buy) on products used in a MO,
add the link between the MO source and the PO generated.
Also add links between MO's when MTO+manufacturing.

task-1913392

closes odoo/odoo#43366

Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
2020-01-24 12:04:47 +00:00
William Henrotin 139f6b1f55 [FIX] purchase_mrp: return string instead or recordset
Commit e923058 aims to ensure the key 'created_purchase_line_id is
returned only if the move as this field filled. The issue is due to
the way python compare falsy object.
   a = b and c    will return b (not False) if b is falsy
                  will return c if neither b nor c are falsy.

If move_raw_id passed in the method doesn't have created_purchase_line_id
   iterate_key = purchase.line.id() or 'created_purchase_line_id'
               = purchase.line.id()
which is not correct as the method should return a string or False.

closes odoo/odoo#43320

Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
2020-01-15 08:52:21 +00:00
Arnold Moyaux e923058568 [FIX] purchase_mrp: ensure that a purchase order is linked
closes odoo/odoo#41115

Related: odoo/enterprise#7177
Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
2020-01-09 16:09:12 +00:00
Adrian Torres 4b38cc6590 [REM] *: calls to @api.multi
Multi is the default api for methods, it is not necessary to explicitly
decorate methods with it, adds clutter and most people use it because
they see that the rest of the code uses it.

Done with `find . -type f -name '*.py' | xargs sed -i '/@api.multi/d'`
2019-07-17 14:13:12 +02:00
Arnaud Baes 8298142574 [IMP] mrp, purchase_mrp: Quantity received for kits in a PO
This commit generalize the method made for computing the quantity delivered in a sale order
in order to be used for the quantity received for a kit in a purchase order.

TaskID: 1929518
2019-01-25 09:00:55 +00:00
Arnaud Baes efb255246b [REF] mrp, purchase_mrp: find bom depending on its type
This commit refactors the method '_bom_find' in order to search bom based on their type.
This allows to handle the cases where a Kit has the route 'Manufacture' set.

TaskID: 1863856
2018-12-19 10:50:29 +00:00
arbaes 04ccd15b70 [IMP] mrp: quantity_done on kits in immediate transfers
With this commit, when a kit is processed trough an immediate transfer,
the quantity done set on the kit is now propagated to its components.

TaskID: 1896772

closes odoo/odoo#28998
2018-12-04 10:51:32 +00:00
jem-odoo 3e3d6c3ce0 [REF] purchase_*: change received qty api
The received quantity on Purchase Order line can be compared
to the delivered qty on Sales Order line. It is now time for
both to share the same mecanism (introduced in
3bf8a62e0d).

This commit sets `qty_received` as a computed field, depending
of a method (`qty_received_method` field) to compute it. The
value can be computed based on
 - manual value; for services (all the time), and consummable
 products (when stock is not installed).
 - stock moves; for stockable and consummable products (when
 stock is installed)

This is now easier to extend the way the received quantity
need to be computed (like in sale).

Task #1850689

closes odoo/odoo#27663
2018-10-30 12:43:53 +00:00
Christophe Simonis b81c2bce84 [MERGE] forward port branch saas-11.4 up to 3c108977c1 2018-10-22 16:59:51 +02:00
Christophe Simonis 1ade6675c3 [MERGE] forward port branch 11.0 up to 717f458394 2018-10-11 16:29:46 +02:00
Goffin Simon d211ea5f7c [FIX] purchase_mrp: Received Quantity in Purchase Order remains '0'
Steps to reproduce the bug:

- Create Product P: with BOM type - Kit and BOM components > Set - Invoicing: on delivered quantity
- Create PO with P and confirm - shipment 1 will be generated
- Cancel the PO - shipment 1 - will also get canceled
- Reset the canceled PO to quotation and confirm it - new shipment 2 will be generated
- Validate the shipment and receive product KIT

Bug:

Check PO - 'Received Qty' was not updated

Inspired from: https://github.com/odoo/odoo/commit/c2dfdc3081764a492a94024f1fb57e15636b04c9

opw:1889303

closes odoo/odoo#27622
2018-10-10 11:34:37 +00:00
Arnold Moyaux 107b275a18 [IMP] mrp: log activity
Pickings/MO/SO/PO can be linked. Only the increased quantity is
propagated between documents. However their ordered quantities can
also be decrease or they can be cancel. In this case an activity
is created on impacted documents in order to describe the situation
and inform the user that a manual action is probably require.

Also in order to propagate the increased quantity from a MO, we have
to do important modification in MRP and we want to avoid doing it before a
major release. That's why increased quantity on a MO also work with
activity at the moment.
2018-08-13 15:38:34 +02:00
Goffin Simon 487873f170 [FIX] purchase: Error when updating dropship order
Steps to reproduce the issue:

- change the demo user settings -> use Sales: User: All Documents only
- create a stockable product with dropship feature on and a supplier
- connect as the demo user
- create a sales order with this product
- confirm the order
- as the admin user, confirm the purchase order generated through dropship
- connect as the demo user
- open the confirmed SO
- add a line with this product
- save the SO

Bug:

An access rights error was raised.

opw:1866015
2018-07-19 11:12:09 +02:00
Christophe Simonis c703a2a0c3 [MERGE] forward port branch 11.0 up to d279a3e6d5 2017-11-16 17:55:37 +01:00
Simon Lejeune 99b9874ab3 [FIX] mrp, purchase_mrp: purchase_line_id also with kits
When confirming a move for a kit, it is basically unlinked and replaced
by moves for its component. The link to the purchase line was kept in
v10, but since rev[1] it is not anymore. Make an helper to get the
values and override it in purchase_mrp to add the purchase line link.

[1] https://github.com/odoo/odoo/commit/8248f0e153ae5fcc1449d0d05149b61df615ad4f

opw 779497
2017-11-14 17:44:15 +01:00
Pierre Masereel 2d3e6d7383 [IMP] purchase: edit received quantity on purchase_line when type service
When we purchase products of type services,the received quantity is
always set to the ordered quantity.

We want to be able to manually enter a received quantity on service
products to have a better trace of what have been received or not.

We show the picking stat button olnly if there are picking

We show the columns qty_received, qty_invoiced and invoice_status
depending on the parent state, and not depending on the context passed
in the menu item.
2017-11-08 15:28:07 +01: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
Nicolas Martinelli 0a5a423bff [FIX] sale_mrp, purchase_mrp: delivered quantity
- Create a manufactured Product A (sold as kit), invoicing based on
  delivered quantity.
- Create the associated BOM, e.g. contains 2 Products B.
- Create a SO with Product A, validate
- Change the BOM so it contains 2 Products C
- Validate the picking linked to the SO

The delivered quantity is not updated since the delivered products (B)
are not the same than the products of the BOM.

This should not be the case. Changing a BOM should not affect the
invoicing. To solve this, we simplify the check and only verifies that
all moves are done.

The same change is applied for PO.
2017-02-02 15:47:21 +01:00
Christophe Simonis a7ba6cde9c [MERGE] forward port branch saas-12 up to 7134aff 2016-09-28 16:28:31 +02:00
Josse Colpaert 153a6d0814 [FIX] mrp: correct interpretation of explode's quantity parameter
In previous versions, the quantity passed to the bom_explode was the number
of times you needed to count the BoM.  If the BoM was for 2 dozens and you pass
48 units, 2 was passed to the bom_explode method.  We are now doing the same
for the explode method and we check it is called this way everywhere.
2016-09-28 12:38:13 +02:00
Thibault Delavallée 0f0ca1c133 [REF] product_uom, *: clean quantity computation methods
product_uom._compute_quantity is an ensure one multi method taking a browse
record as second paramter. It replaces _compute_qty and _compute_qty_obj
to have a single and standard computation method.
2016-08-01 15:05:32 +02:00
Josse Colpaert 2ddc35a530 [REF][NEWPIE] mrp: new MRP
This commit contains the core of the new MRP. It contains a whole refactoring
of the MRP application, with improved and new features, written in new API.
Among other here are the main manufacturing workflow improvements :

 - Picking type not only for pickings but also for manufacturing orders
 - Properties replaced by picking type
 - BoM can only be produced with its routing (no other)
 - Either produce without routing with only production orders, or produce with
   routing
 - By default, there is an order in the work orders (serially), but you can
   override it to be able to work in parallel
 - Time clocking on work orders and block time on work centers with reporting
   on OEE, performance, losses, ...
 - Real-time adaptation of timings on operations
 - Lots/serial numbers can be inputted like in the pickings on manufacturing
   orders.  It is also possible to input them in the work orders.
 - Material availability independent of production order state (possibility to
   start production when only part of it is there)
 - Work sheets on work orders
 - Put messages on work orders to make your workers pay attention to something
 - Full traceability link to see for each produced piece of stock, the
   consumed pieces, ...
 - Separate scrap object (a scrap is not done based on an original move
   anymore)
 - Separate unbuild system (if you want to unbuild into its original
   components)

Thanks to all people that helped during this development, notably but not
limited to Chirag A Dodiya (cod@odoo.com), Gaurav Panchal (gan@odoo.com),
Jignesh Rathod (jir@odoo.com), Mansi Trivedi (mtr@odoo.com), Pariket Trivedi
(ptr@odoo.com).
2016-07-04 16:22:37 +02:00