Skip to content

Instantly share code, notes, and snippets.

View sle-odoo's full-sized avatar

Simon Lejeune sle-odoo

View GitHub Profile
@sle-odoo
sle-odoo / gist:6f8f1704eaad4b99101098643dc838ba
Created December 2, 2019 12:44
_get_returnable_quantities on stock.move
def _get_returnable_quantities(self, lot=None, package=None):
"""Return the `stock.move.line` of `self` still returnable.
When computing the quantities to return, this method handles the existing returns, returns
of returns, and so on.
:param lot: `stock.production.lot` record to filter candidate move lines
:param package: `stock.quant.package` record to filter candidate move lines
:return: a dict of the quantities of `stock_move` stille returnable, indexed by
`stock.production.lot` and `stock.quant.package`
:rtype: dict
"""
quants = env['stock.quant'].search([])
warning = ''
for quant in quants:
move_lines = env["stock.move.line"].search([
('product_id', '=', quant.product_id.id),
('location_id', '=', quant.location_id.id),
('lot_id', '=', quant.lot_id.id),
('package_id', '=', quant.package_id.id),
('owner_id', '=', quant.owner_id.id),