mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[14.0][IMP]rma_put_away: allows to do stock moves from rma
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
from . import rma_order_line
|
||||
from . import rma_operation
|
||||
from . import stock_picking
|
||||
|
||||
@@ -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):
|
||||
|
||||
13
rma_put_away/models/stock_picking.py
Normal file
13
rma_put_away/models/stock_picking.py
Normal file
@@ -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"
|
||||
)
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
<tree string="RMA Lines" editable="bottom" create="false">
|
||||
<field name="rma_id" groups="rma.group_rma_groups" />
|
||||
<field name="product_id" />
|
||||
<field name="product_qty" />
|
||||
<field name="product_qty"/>
|
||||
<field name="qty_to_receive" />
|
||||
<field name="line_id" invisible="1" />
|
||||
<field name="uom_id" groups="uom.group_uom" />
|
||||
</tree>
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user