diff --git a/rma_put_away/__manifest__.py b/rma_put_away/__manifest__.py index 5bb1cda2..843e59d4 100644 --- a/rma_put_away/__manifest__.py +++ b/rma_put_away/__manifest__.py @@ -3,7 +3,7 @@ "version": "14.0.1.0.0", "license": "LGPL-3", "category": "RMA", - "summary": "Allows to put away the recieved products" + "summary": "Allows to put away the received products" "in odoo", "author": "ForgeFlow", "website": "https://github.com/ForgeFlow/stock-rma", diff --git a/rma_put_away/models/__init__.py b/rma_put_away/models/__init__.py index b1fae22f..39c6dbdc 100644 --- a/rma_put_away/models/__init__.py +++ b/rma_put_away/models/__init__.py @@ -1,2 +1,3 @@ from . import rma_order_line from . import rma_operation +from . import stock_picking diff --git a/rma_put_away/models/rma_order_line.py b/rma_put_away/models/rma_order_line.py index 2cb7a24c..de8c579c 100644 --- a/rma_put_away/models/rma_order_line.py +++ b/rma_put_away/models/rma_order_line.py @@ -4,6 +4,15 @@ from odoo import _, api, fields, models class RmaOrderLine(models.Model): _inherit = "rma.order.line" + picking_ids = fields.One2many( + comodel_name="stock.picking", + inverse_name="rma_line_id", + string="Pickings", + readonly=True, + states={"draft": [("readonly", False)]}, + copy=False, + ) + qty_to_put_away = fields.Float( string="Qty To Put Away", digits="Product Unit of Measure", @@ -33,17 +42,21 @@ class RmaOrderLine(models.Model): @api.depends("qty_to_receive", "qty_put_away") def _compute_qty_to_put_away(self): - for rec in self: - rec.qty_to_put_away = 0.0 - if rec.put_away_policy == "ordered": - rec.qty_to_put_away = max(rec.product_qty - rec.qty_put_away, 0) - elif rec.put_away_policy == "received": - rec.qty_to_put_away = max(rec.qty_received - rec.qty_put_away, 0) + self.qty_to_put_away = 0.0 + if self.put_away_policy == "ordered": + self.qty_to_put_away = max(self.product_qty - self.qty_put_away, 0) + elif self.put_away_policy == "received": + self.qty_to_put_away = max(self.qty_received - self.qty_put_away, 0) @api.depends("qty_to_receive") def _compute_qty_put_away(self): - for rec in self: - rec.qty_put_away = 0 + self.qty_put_away = 0.0 + for pick in self.picking_ids.filtered(lambda p: p.state == "done"): + repair_qty = self.uom_id._compute_quantity( + pick.product_qty, pick.product_uom + ) + self.qty_put_away += repair_qty + return self.qty_put_away @api.onchange("operation_id") def _onchange_operation_id(self): diff --git a/rma_put_away/models/stock_picking.py b/rma_put_away/models/stock_picking.py new file mode 100644 index 00000000..04729824 --- /dev/null +++ b/rma_put_away/models/stock_picking.py @@ -0,0 +1,13 @@ +# Copyright 2020-21 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + rma_line_id = fields.Many2one( + comodel_name="rma.order.line", string="RMA", ondelete="restrict" + ) + diff --git a/rma_put_away/views/rma_put_away_view.xml b/rma_put_away/views/rma_put_away_view.xml index a489a774..79e002ac 100644 --- a/rma_put_away/views/rma_put_away_view.xml +++ b/rma_put_away/views/rma_put_away_view.xml @@ -10,7 +10,8 @@ - + + diff --git a/rma_put_away/wizards/rma_make_put_away.py b/rma_put_away/wizards/rma_make_put_away.py index 99516110..3fe13b3a 100644 --- a/rma_put_away/wizards/rma_make_put_away.py +++ b/rma_put_away/wizards/rma_make_put_away.py @@ -9,7 +9,11 @@ class RmaMakePutAway(models.TransientModel): _name = "rma_make_put_away.wizard" _description = "Wizard to create put away from rma lines" - item_ids = fields.One2many("rma_make_picking.wizard.item", "wiz_id", string="Items") + item_ids = fields.One2many( + comodel_name="rma_make_put_away.wizard.item", + inverse_name="wiz_id", + string="Items", + ) @api.returns("rma.order.line") def _prepare_item(self, line): @@ -63,10 +67,6 @@ class RmaMakePutAway(models.TransientModel): line = item.line_id if line.state != "approved": raise ValidationError(_("RMA %s is not approved") % line.name) - if line.receipt_policy == "no" and picking_type == "incoming": - raise ValidationError(_("No shipments needed for this operation")) - if line.delivery_policy == "no" and picking_type == "outgoing": - raise ValidationError(_("No deliveries needed for this operation")) procurement = self._create_procurement(item, picking_type) procurements.extend(procurement) return procurements @@ -100,10 +100,8 @@ class RmaMakePutAway(models.TransientModel): @api.model def _get_procurement_data(self, item, group, qty, picking_type): line = item.line_id - delivery_address_id = self._get_address(item) - location = self._get_address_location(delivery_address_id, line.type) - warehouse = line.out_warehouse_id - route = line.out_route_id + warehouse = line.operation_id.internal_warehouse_id + route = line.operation_id.internal_route_id if not route: raise ValidationError(_("No route specified")) if not warehouse: @@ -116,11 +114,12 @@ class RmaMakePutAway(models.TransientModel): "date_planned": time.strftime(DT_FORMAT), "product_id": item.product_id, "product_qty": qty, - "partner_id": delivery_address_id.id, +# "partner_id": delivery_address_id.id, "product_uom": line.product_id.product_tmpl_id.uom_id.id, - "location_id": location, +# "location_id": location, "rma_line_id": line.id, "route_ids": route, + "company_id": line.company_id } return procurement_data @@ -166,7 +165,7 @@ class RmaMakePutAway(models.TransientModel): [("rma_line_id", "=", item.line_id.id)] ) - def _get_procurement_group_data(self, item): + def _get_procurement_group_data_put_away(self, item): group_data = { "partner_id": item.line_id.partner_id.id, "name": item.line_id.rma_id.name or item.line_id.name, @@ -175,3 +174,30 @@ class RmaMakePutAway(models.TransientModel): } return group_data + +class RmaMakePutAwayItem(models.TransientModel): + _name = "rma_make_put_away.wizard.item" + _description = "Items to Put Away" + + wiz_id = fields.Many2one("rma_make_put_away.wizard", string="Wizard", required=True) + line_id = fields.Many2one( + "rma.order.line", string="RMA order Line", ondelete="cascade" + ) + rma_id = fields.Many2one("rma.order", related="line_id.rma_id", string="RMA Group") + product_id = fields.Many2one("product.product", string="Product") + product_qty = fields.Float( + related="line_id.product_qty", + string="Quantity Ordered", + copy=False, + digits="Product Unit of Measure", + ) + qty_to_receive = fields.Float( + string="Quantity to Receive", digits="Product Unit of Measure" + ) + qty_to_deliver = fields.Float( + string="Quantity To Deliver", digits="Product Unit of Measure" + ) + uom_id = fields.Many2one("uom.uom", string="Unit of Measure") + + +