From aeeff89d9297d2d3495d829012cedfd2a8361554 Mon Sep 17 00:00:00 2001 From: oihane Date: Mon, 2 Mar 2015 16:42:46 +0100 Subject: [PATCH] [ADD] New module closes #693 First upload, merge quants --- README.rst | 4 ++++ __init__.py | 6 ++++++ __openerp__.py | 36 ++++++++++++++++++++++++++++++++++++ models/__init__.py | 6 ++++++ models/stock.py | 29 +++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 README.rst create mode 100644 __init__.py create mode 100644 __openerp__.py create mode 100644 models/__init__.py create mode 100644 models/stock.py diff --git a/README.rst b/README.rst new file mode 100644 index 000000000..56450f78e --- /dev/null +++ b/README.rst @@ -0,0 +1,4 @@ +Quant merge +=========== + +This module allows to merge diferent quants if they meet some requirements. \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 000000000..054c8853d --- /dev/null +++ b/__init__.py @@ -0,0 +1,6 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from . import models diff --git a/__openerp__.py b/__openerp__.py new file mode 100644 index 000000000..5a1e8550a --- /dev/null +++ b/__openerp__.py @@ -0,0 +1,36 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +############################################################################## + +{ + "name": "Stock - Quant merge", + "version": "1.0", + "depends": [ + "stock", + ], + "author": "OdooMRP team", + "website": "http://www.odoomrp.com", + "contributors": [ + "Oihane Crucelaegui ", + "Pedro M. Baeza ", + "Ana Juaristi " + ], + "category": "Warehouse Management", + "summary": "", + "data": [], + "installable": True, +} diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 000000000..055886a14 --- /dev/null +++ b/models/__init__.py @@ -0,0 +1,6 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from . import stock diff --git a/models/stock.py b/models/stock.py new file mode 100644 index 000000000..8102185f2 --- /dev/null +++ b/models/stock.py @@ -0,0 +1,29 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## + +from openerp import models, api + + +class StockQuant(models.Model): + _inherit = 'stock.quant' + + @api.one + def merge_stock_quants(self): + if not self.reservation_id: + quants = self.search( + [('id', '!=', self.id), + ('product_id', '=', self.product_id.id), + ('lot_id', '=', self.lot_id.id), + ('package_id', '=', self.package_id.id), + ('location_id', '=', self.location_id.id), + ('reservation_id', '=', False), + ('propagated_from_id', '=', False)]) + qty = cost = 0 + for quant in quants: + qty += quant.qty + cost += quant.cost + quant.unlink() + self.cost += cost + self.qty += qty