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

serial unicity #30088

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
5 participants
@Whenrow
Copy link
Contributor

Whenrow commented Jan 9, 2019

Description of the issue/feature this PR addresses:

Current behavior before PR:

Desired behavior after PR is merged:

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo robodoo added the seen 🙂 label Jan 9, 2019

@C3POdoo C3POdoo added the RD label Jan 9, 2019

@robodoo robodoo added the CI 🤖 label Jan 9, 2019

@Whenrow Whenrow requested a review from sle-odoo Jan 10, 2019

addons/stock/models/stock_move_line.py Outdated
('quantity', '>', 0)
])
if similar_quant > 1:
raise ValidationError(_('You already have product %s with serial number %s.' % (ml.product_id.display_name, ml.lot_id.name)))

This comment has been minimized.

@sle-odoo

sle-odoo Jan 10, 2019

Contributor

UserError
don't like the error message but can't really think of better atm, maybe something like
"You cannot move product XX having a serial XX as it is already present elsewhere and the combination should be unique."

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch Jan 10, 2019

@robodoo robodoo removed the CI 🤖 label Jan 10, 2019

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch Jan 10, 2019

@robodoo robodoo added the CI 🤖 label Jan 10, 2019

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch Jan 11, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Jan 11, 2019

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch Jan 15, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Jan 15, 2019

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch Jan 16, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Jan 16, 2019

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch 2 times, most recently Jan 16, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Jan 17, 2019

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch Jan 21, 2019

@robodoo robodoo removed the CI 🤖 label Jan 21, 2019

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch 2 times, most recently Jan 22, 2019

@robodoo robodoo added the CI 🤖 label Jan 22, 2019

addons/mrp/models/stock_move.py Outdated
# ])
# if similar_ml:
# raise UserError(_('You already produced the serial number %s for product %s' % (line.lot_id.name, line.product_id.name)))
# return super(StockMoveLine, self)._action_done(cancel_backorder)

This comment has been minimized.

@sle-odoo

sle-odoo Jan 24, 2019

Contributor

tcheuuu

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch Jan 24, 2019

@robodoo robodoo removed the CI 🤖 label Jan 24, 2019

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch 2 times, most recently to 0fbc8a2 Jan 29, 2019

@robodoo robodoo added the CI 🤖 label Jan 30, 2019

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch from 0fbc8a2 to 4711703 Jan 30, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Jan 30, 2019

@@ -356,6 +402,7 @@ class InventoryLine(models.Model):
inventory_location_id = fields.Many2one(
'stock.location', 'Inventory Location', related='inventory_id.location_id', related_sudo=False, readonly=False)
product_tracking = fields.Selection('Tracking', related='product_id.tracking', readonly=True)
correction_line = fields.Selection([('none', None), ('warning', 'Warning'), ('danger', 'Danger')], default='none')

This comment has been minimized.

@amoyaux

amoyaux Feb 8, 2019

Contributor

Use False instead of None


# Unicity of serial tracked product. Search in quants if the sn is
# already present in stock or delivered to a customer
if ml.tracking == 'serial' and ml.lot_id: # see test_inventory_4:

This comment has been minimized.

@amoyaux

amoyaux Feb 8, 2019

Contributor

remove the ref to the test. The comments are already make sense

else:
similar_quant = similar_quant[0]
# Fill the wizard lines
if similar_quant and similar_quant.quantity - sum(self.line_ids.filtered(lambda line: line.correction_line == 'warning' and line.prod_lot_id == similar_quant.lot_id).mapped('theoretical_qty')) != 0:

This comment has been minimized.

@amoyaux

amoyaux Feb 8, 2019

Contributor

I would remove the line.correction_line == 'warning' if the user did a manual correction?

if same_usage:
similar_quant = same_usage[0]
else:
similar_quant = similar_quant[0]

This comment has been minimized.

@amoyaux

amoyaux Feb 8, 2019

Contributor

Seems hazardous

@amoyaux

This comment has been minimized.

Copy link
Contributor

amoyaux commented Feb 8, 2019

There is no check if the user unlock write on done ml.

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch from 4711703 to 1ec67c5 Feb 11, 2019

@robodoo robodoo removed the CI 🤖 label Feb 11, 2019

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch from 1ec67c5 to f01d502 Feb 11, 2019

[FIX] stock: block any duplicate serial numbers
Serial numbers should be unique by design. There are currently some checks
to empeach any duplication into transfers, inventory adjustements or production.
However, a global constraint checking accross all quants is missing. Indeed,
nothing blocks you to have the same serial number used in two sub locations of
your stock. You can also deliver a tracked product then produce the same number.

This commit adds a constraint at the stock move lines validation. After the creation of
the quant (as it's tracked by serial number, it should always be a creation and
not an update). We check that the serial number is not present elsewhere except in
location 'supplier', 'production' and 'inventory. Those 3 last one are virtuals ones
and the quantity is most of the time negatives.

This commit also add a correction process for inventory adjutment. If a serial number
is stored in loc1 and the inventory aims to change quantity to 1 for sn1 in loc2.
We raise a correction wizard to warn the user there is a problem and to add in the
inventory some line to balance the new stock moves.

Ex: we produce sn1, we sell it to a customer. The quant situation is the following
Production : -1
Customer   : +1
We create an inventory adjustement to increase the quantity of sn1 in Stock. Without
the commit, the situation whould have been
Production : -1
Inventory  : -1
Customer   : +1
Stock      : +1
What it does is inverting the first movement (stock -> customer) thanks to an inventory line
The situation after the inventory is the following
Production : -1
Stock      : +1

Task : 1924758

@Whenrow Whenrow force-pushed the odoo-dev:master-serial-unicity-whe branch from f01d502 to e9d9c19 Feb 14, 2019

@robodoo robodoo added the CI 🤖 label Feb 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment