mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[MIG] rma: Migration to 13.0
This commit is contained in:
committed by
JasminSForgeFlow
parent
d321342e8f
commit
2a42cc17ff
@@ -1,4 +1,4 @@
|
||||
# Copyright (C) 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# Copyright (C) 2017 ForgeFlow
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
import time
|
||||
@@ -7,8 +7,6 @@ from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT as DT_FORMAT
|
||||
|
||||
import odoo.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class RmaMakePicking(models.TransientModel):
|
||||
_name = "rma_make_picking.wizard"
|
||||
@@ -95,10 +93,10 @@ class RmaMakePicking(models.TransientModel):
|
||||
return delivery_address
|
||||
|
||||
@api.model
|
||||
def _get_address_location(self, delivery_address_id, type):
|
||||
if type == "supplier":
|
||||
def _get_address_location(self, delivery_address_id, a_type):
|
||||
if a_type == "supplier":
|
||||
return delivery_address_id.property_stock_supplier
|
||||
elif type == "customer":
|
||||
elif a_type == "customer":
|
||||
return delivery_address_id.property_stock_customer
|
||||
|
||||
@api.model
|
||||
@@ -150,27 +148,33 @@ class RmaMakePicking(models.TransientModel):
|
||||
else:
|
||||
qty = item.qty_to_deliver
|
||||
values = self._get_procurement_data(item, group, qty, picking_type)
|
||||
values = dict(values, rma_line_id=item.line_id, rma_id=item.line_id.rma_id)
|
||||
# create picking
|
||||
procurements = []
|
||||
try:
|
||||
self.env["procurement.group"].run(
|
||||
procurement = group.Procurement(
|
||||
item.line_id.product_id,
|
||||
qty,
|
||||
item.line_id.product_id.product_tmpl_id.uom_id,
|
||||
values.get("location_id"),
|
||||
values.get("origin"),
|
||||
values.get("origin"),
|
||||
self.env.company,
|
||||
values,
|
||||
)
|
||||
|
||||
procurements.append(procurement)
|
||||
self.env["procurement.group"].run(procurements)
|
||||
except UserError as error:
|
||||
errors.append(error.name)
|
||||
if errors:
|
||||
raise UserError("\n".join(errors))
|
||||
return values.get("origin")
|
||||
return procurements
|
||||
|
||||
@api.multi
|
||||
def _create_picking(self):
|
||||
"""Method called when the user clicks on create picking"""
|
||||
picking_type = self.env.context.get("picking_type")
|
||||
procurements = []
|
||||
for item in self.item_ids:
|
||||
line = item.line_id
|
||||
if line.state != "approved":
|
||||
@@ -180,43 +184,18 @@ class RmaMakePicking(models.TransientModel):
|
||||
if line.delivery_policy == "no" and picking_type == "outgoing":
|
||||
raise ValidationError(_("No deliveries needed for this operation"))
|
||||
procurement = self._create_procurement(item, picking_type)
|
||||
return procurement
|
||||
procurements.extend(procurement)
|
||||
return procurements
|
||||
|
||||
@api.model
|
||||
def _get_action(self, pickings, procurements):
|
||||
if pickings and procurements:
|
||||
action = procurements.do_view_pickings()
|
||||
else:
|
||||
action = self.env.ref("procurement.procurement_order_action_exceptions")
|
||||
action = action.read()[0]
|
||||
if procurements:
|
||||
# choose the view_mode accordingly
|
||||
if len(procurements.ids) <= 1:
|
||||
res = self.env.ref("procurement.procurement_form_view", False)
|
||||
action["views"] = [(res and res.id or False, "form")]
|
||||
action["res_id"] = procurements.ids[0]
|
||||
else:
|
||||
action["domain"] = [("id", "in", procurements.ids)]
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def action_create_picking(self):
|
||||
procurement = self._create_picking()
|
||||
action = self.env.ref("stock.do_view_pickings")
|
||||
action = action.read()[0]
|
||||
if procurement:
|
||||
pickings = (
|
||||
self.env["stock.picking"].search([("origin", "=", procurement)]).ids
|
||||
)
|
||||
if len(pickings) > 1:
|
||||
action["domain"] = [("id", "in", pickings)]
|
||||
else:
|
||||
form = self.env.ref("stock.view_picking_form", False)
|
||||
action["views"] = [(form and form.id or False, "form")]
|
||||
action["res_id"] = pickings and pickings[0]
|
||||
self._create_picking()
|
||||
picking_type = self.env.context.get("picking_type")
|
||||
if picking_type == "outgoing":
|
||||
action = self.item_ids.line_id.action_view_out_shipments()
|
||||
else:
|
||||
action = self.item_ids.line_id.action_view_in_shipments()
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def action_cancel(self):
|
||||
return {"type": "ir.actions.act_window_close"}
|
||||
|
||||
@@ -237,13 +216,13 @@ class RmaMakePickingItem(models.TransientModel):
|
||||
related="line_id.product_qty",
|
||||
string="Quantity Ordered",
|
||||
copy=False,
|
||||
digits=dp.get_precision("Product Unit of Measure"),
|
||||
digits="Product Unit of Measure",
|
||||
readonly=True,
|
||||
)
|
||||
qty_to_receive = fields.Float(
|
||||
string="Quantity to Receive", digits=dp.get_precision("Product Unit of Measure")
|
||||
string="Quantity to Receive", digits="Product Unit of Measure"
|
||||
)
|
||||
qty_to_deliver = fields.Float(
|
||||
string="Quantity To Deliver", digits=dp.get_precision("Product Unit of Measure")
|
||||
string="Quantity To Deliver", digits="Product Unit of Measure"
|
||||
)
|
||||
uom_id = fields.Many2one("uom.uom", string="Unit of Measure", readonly=True)
|
||||
|
||||
Reference in New Issue
Block a user