mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[FIX] Travis
This commit is contained in:
committed by
Chanakya Soni
parent
e6a0cdcabc
commit
55c0b05234
@@ -2,21 +2,21 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
{
|
||||
'name': 'RMA Purchase',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'RMA',
|
||||
'summary': 'RMA from PO',
|
||||
'license': 'LGPL-3',
|
||||
'author': 'Eficent, Odoo Community Association (OCA)',
|
||||
'website': 'https://github.com/Eficent/stock-rma',
|
||||
'depends': ['rma_account', 'purchase'],
|
||||
'data': [
|
||||
'wizards/rma_order_line_make_purchase_order_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'views/rma_operation_view.xml',
|
||||
'views/rma_order_view.xml',
|
||||
'views/rma_order_line_view.xml',
|
||||
'wizards/rma_add_purchase.xml',
|
||||
"name": "RMA Purchase",
|
||||
"version": "13.0.1.0.0",
|
||||
"category": "RMA",
|
||||
"summary": "RMA from PO",
|
||||
"license": "LGPL-3",
|
||||
"author": "Eficent, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/Eficent/stock-rma",
|
||||
"depends": ["rma_account", "purchase"],
|
||||
"data": [
|
||||
"wizards/rma_order_line_make_purchase_order_view.xml",
|
||||
"security/ir.model.access.csv",
|
||||
"views/rma_operation_view.xml",
|
||||
"views/rma_order_view.xml",
|
||||
"views/rma_order_line_view.xml",
|
||||
"wizards/rma_add_purchase.xml",
|
||||
],
|
||||
'installable': True,
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
@@ -11,16 +11,18 @@ class PurchaseOrder(models.Model):
|
||||
def new(self, vals):
|
||||
"""Allows to propose a line based on the RMA information."""
|
||||
res = super(PurchaseOrder, self).new(vals)
|
||||
rma_line_id = self.env.context.get('rma_line_id')
|
||||
rma_line_id = self.env.context.get("rma_line_id")
|
||||
if rma_line_id:
|
||||
rma_line = self.env['rma.order.line'].browse(rma_line_id)
|
||||
line = self.env['purchase.order.line'].new({
|
||||
'product_id': rma_line.product_id.id,
|
||||
})
|
||||
rma_line = self.env["rma.order.line"].browse(rma_line_id)
|
||||
line = self.env["purchase.order.line"].new(
|
||||
{"product_id": rma_line.product_id.id}
|
||||
)
|
||||
line.onchange_product_id()
|
||||
line.update({
|
||||
'product_qty': rma_line.qty_to_purchase,
|
||||
'product_uom': rma_line.uom_id.id,
|
||||
})
|
||||
line.update(
|
||||
{
|
||||
"product_qty": rma_line.qty_to_purchase,
|
||||
"product_uom": rma_line.uom_id.id,
|
||||
}
|
||||
)
|
||||
res.order_line = line
|
||||
return res
|
||||
|
||||
@@ -7,53 +7,71 @@ from odoo import api, fields, models
|
||||
class PurchaseOrderLine(models.Model):
|
||||
_inherit = "purchase.order.line"
|
||||
|
||||
rma_line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA',
|
||||
)
|
||||
rma_line_id = fields.Many2one(comodel_name="rma.order.line", string="RMA",)
|
||||
|
||||
@api.model
|
||||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||||
def name_search(self, name="", args=None, operator="ilike", limit=100):
|
||||
"""Allows to search by PO reference."""
|
||||
if not args:
|
||||
args = []
|
||||
args += ['|',
|
||||
(self._rec_name, operator, name),
|
||||
('order_id.name', operator, name)]
|
||||
args += [
|
||||
"|",
|
||||
(self._rec_name, operator, name),
|
||||
("order_id.name", operator, name),
|
||||
]
|
||||
return super(PurchaseOrderLine, self).name_search(
|
||||
name=name, args=args, operator=operator, limit=limit)
|
||||
name=name, args=args, operator=operator, limit=limit
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _name_search(self, name='', args=None, operator='ilike',
|
||||
limit=100, name_get_uid=None):
|
||||
def _name_search(
|
||||
self, name="", args=None, operator="ilike", limit=100, name_get_uid=None
|
||||
):
|
||||
"""Typed text is cleared here for better extensibility."""
|
||||
return super(PurchaseOrderLine, self)._name_search(
|
||||
name='', args=args, operator=operator, limit=limit,
|
||||
name_get_uid=name_get_uid)
|
||||
name="",
|
||||
args=args,
|
||||
operator=operator,
|
||||
limit=limit,
|
||||
name_get_uid=name_get_uid,
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
res = []
|
||||
if self.env.context.get('rma'):
|
||||
if self.env.context.get("rma"):
|
||||
for purchase in self:
|
||||
invoices = self.env['account.invoice.line'].search(
|
||||
[('purchase_line_id', '=', purchase.id)])
|
||||
invoices = self.env["account.invoice.line"].search(
|
||||
[("purchase_line_id", "=", purchase.id)]
|
||||
)
|
||||
if purchase.order_id.name:
|
||||
res.append((purchase.id, "%s %s %s qty:%s" % (
|
||||
purchase.order_id.name,
|
||||
" ".join(str(x) for x in [
|
||||
inv.number for inv in invoices.mapped(
|
||||
'invoice_id')]),
|
||||
purchase.product_id.name, purchase.product_qty)))
|
||||
else:
|
||||
res.append(
|
||||
super(PurchaseOrderLine, purchase).name_get()[0])
|
||||
(
|
||||
purchase.id,
|
||||
"%s %s %s qty:%s"
|
||||
% (
|
||||
purchase.order_id.name,
|
||||
" ".join(
|
||||
str(x)
|
||||
for x in [
|
||||
inv.number
|
||||
for inv in invoices.mapped("invoice_id")
|
||||
]
|
||||
),
|
||||
purchase.product_id.name,
|
||||
purchase.product_qty,
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
res.append(super(PurchaseOrderLine, purchase).name_get()[0])
|
||||
return res
|
||||
else:
|
||||
return super(PurchaseOrderLine, self).name_get()
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
rma_line_id = self.env.context.get('rma_line_id')
|
||||
rma_line_id = self.env.context.get("rma_line_id")
|
||||
if rma_line_id:
|
||||
vals['rma_line_id'] = rma_line_id
|
||||
vals["rma_line_id"] = rma_line_id
|
||||
return super(PurchaseOrderLine, self).create(vals)
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RmaOperation(models.Model):
|
||||
_inherit = 'rma.operation'
|
||||
_inherit = "rma.operation"
|
||||
|
||||
purchase_policy = fields.Selection(
|
||||
selection=[('no', 'Not required'),
|
||||
('ordered', 'Based on Ordered Quantities'),
|
||||
('delivered', 'Based on Delivered Quantities')],
|
||||
string="Purchase Policy", default='no',
|
||||
selection=[
|
||||
("no", "Not required"),
|
||||
("ordered", "Based on Ordered Quantities"),
|
||||
("delivered", "Based on Delivered Quantities"),
|
||||
],
|
||||
string="Purchase Policy",
|
||||
default="no",
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@api.constrains('purchase_policy')
|
||||
@api.constrains("purchase_policy")
|
||||
def _check_purchase_policy(self):
|
||||
if self.filtered(
|
||||
lambda r: r.purchase_policy != 'no' and r.type != 'supplier'):
|
||||
raise ValidationError(_(
|
||||
'Purchase Policy can only apply to supplier operations'))
|
||||
if self.filtered(lambda r: r.purchase_policy != "no" and r.type != "supplier"):
|
||||
raise ValidationError(
|
||||
_("Purchase Policy can only apply to supplier operations")
|
||||
)
|
||||
|
||||
@@ -13,42 +13,41 @@ class RmaOrder(models.Model):
|
||||
po_count = 0
|
||||
rma_line_po = []
|
||||
for line in rec.rma_line_ids:
|
||||
rma_line_po += self.env['purchase.order'].search(
|
||||
[('origin', '=', line.name)]).ids
|
||||
rma_line_po += (
|
||||
self.env["purchase.order"].search([("origin", "=", line.name)]).ids
|
||||
)
|
||||
if rma_line_po:
|
||||
po_count = len(list(set(rma_line_po)))
|
||||
rec.po_count = po_count
|
||||
|
||||
@api.multi
|
||||
@api.depends('rma_line_ids')
|
||||
@api.depends("rma_line_ids")
|
||||
def _compute_origin_po_count(self):
|
||||
for rma in self:
|
||||
purchases = rma.mapped(
|
||||
'rma_line_ids.purchase_order_line_id.order_id')
|
||||
purchases = rma.mapped("rma_line_ids.purchase_order_line_id.order_id")
|
||||
rma.origin_po_count = len(purchases)
|
||||
|
||||
po_count = fields.Integer(
|
||||
compute='_compute_po_count', string='# of PO')
|
||||
po_count = fields.Integer(compute="_compute_po_count", string="# of PO")
|
||||
origin_po_count = fields.Integer(
|
||||
compute='_compute_origin_po_count', string='# of Origin PO')
|
||||
compute="_compute_origin_po_count", string="# of Origin PO"
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def action_view_purchase_order(self):
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
action = self.env.ref("purchase.purchase_rfq")
|
||||
result = action.read()[0]
|
||||
po_ids = self.env['purchase.order'].search(
|
||||
[('origin', '=', self.name)]).ids
|
||||
po_ids = self.env["purchase.order"].search([("origin", "=", self.name)]).ids
|
||||
for line in self.rma_line_ids:
|
||||
po_ids += self.env['purchase.order'].search(
|
||||
[('origin', '=', line.name)]).ids
|
||||
result['domain'] = [('id', 'in', po_ids)]
|
||||
po_ids += (
|
||||
self.env["purchase.order"].search([("origin", "=", line.name)]).ids
|
||||
)
|
||||
result["domain"] = [("id", "in", po_ids)]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def action_view_origin_purchase_order(self):
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
action = self.env.ref("purchase.purchase_rfq")
|
||||
result = action.read()[0]
|
||||
po_ids = self.mapped(
|
||||
'rma_line_ids.purchase_order_line_id.order_id').ids
|
||||
result['domain'] = [('id', 'in', po_ids)]
|
||||
po_ids = self.mapped("rma_line_ids.purchase_order_line_id.order_id").ids
|
||||
result["domain"] = [("id", "in", po_ids)]
|
||||
return result
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
from odoo.addons import decimal_precision as dp
|
||||
|
||||
|
||||
@@ -12,16 +13,18 @@ class RmaOrderLine(models.Model):
|
||||
@api.multi
|
||||
def _compute_purchase_count(self):
|
||||
for rec in self:
|
||||
purchase_line_count = self.env['purchase.order.line'].search(
|
||||
[('rma_line_id', '=', rec.id)])
|
||||
rec.purchase_count = len(purchase_line_count.mapped('order_id'))
|
||||
purchase_line_count = self.env["purchase.order.line"].search(
|
||||
[("rma_line_id", "=", rec.id)]
|
||||
)
|
||||
rec.purchase_count = len(purchase_line_count.mapped("order_id"))
|
||||
|
||||
@api.multi
|
||||
def _compute_purchase_order_lines(self):
|
||||
for rec in self:
|
||||
purchase_list = []
|
||||
for line in self.env['purchase.order.line'].search(
|
||||
[('rma_line_id', '=', rec.id)]):
|
||||
for line in self.env["purchase.order.line"].search(
|
||||
[("rma_line_id", "=", rec.id)]
|
||||
):
|
||||
purchase_list.append(line.id)
|
||||
rec.purchase_order_line_ids = [(6, 0, purchase_list)]
|
||||
|
||||
@@ -29,76 +32,90 @@ class RmaOrderLine(models.Model):
|
||||
def _compute_qty_purchase(self):
|
||||
for rec in self:
|
||||
rec.qty_purchased = rec._get_rma_purchased_qty()
|
||||
if rec.purchase_policy == 'ordered':
|
||||
if rec.purchase_policy == "ordered":
|
||||
rec.qty_to_purchase = rec.product_qty - rec.qty_purchased
|
||||
elif rec.purchase_policy == 'delivered':
|
||||
elif rec.purchase_policy == "delivered":
|
||||
rec.qty_to_purchase = rec.qty_delivered - rec.qty_purchased
|
||||
else:
|
||||
rec.qty_to_purchase = 0.0
|
||||
|
||||
purchase_count = fields.Integer(
|
||||
compute='_compute_purchase_count', string='# of Purchases',
|
||||
compute="_compute_purchase_count", string="# of Purchases",
|
||||
)
|
||||
purchase_order_line_id = fields.Many2one(
|
||||
comodel_name='purchase.order.line', string='Originating Purchase Line',
|
||||
ondelete='restrict',
|
||||
readonly=True, states={'draft': [('readonly', False)]},
|
||||
comodel_name="purchase.order.line",
|
||||
string="Originating Purchase Line",
|
||||
ondelete="restrict",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
purchase_id = fields.Many2one(
|
||||
string="Source Purchase Order",
|
||||
related='purchase_order_line_id.order_id',
|
||||
related="purchase_order_line_id.order_id",
|
||||
readonly=True,
|
||||
)
|
||||
purchase_order_line_ids = fields.Many2many(
|
||||
comodel_name='purchase.order.line',
|
||||
relation='purchase_line_rma_line_rel',
|
||||
column1='rma_order_line_id', column2='purchase_order_line_id',
|
||||
string='Purchase Order Lines', compute='_compute_purchase_order_lines',
|
||||
comodel_name="purchase.order.line",
|
||||
relation="purchase_line_rma_line_rel",
|
||||
column1="rma_order_line_id",
|
||||
column2="purchase_order_line_id",
|
||||
string="Purchase Order Lines",
|
||||
compute="_compute_purchase_order_lines",
|
||||
)
|
||||
purchase_policy = fields.Selection(
|
||||
selection=[('no', 'Not required'),
|
||||
('ordered', 'Based on Ordered Quantities'),
|
||||
('delivered', 'Based on Delivered Quantities')],
|
||||
string="Purchase Policy", default='no',
|
||||
selection=[
|
||||
("no", "Not required"),
|
||||
("ordered", "Based on Ordered Quantities"),
|
||||
("delivered", "Based on Delivered Quantities"),
|
||||
],
|
||||
string="Purchase Policy",
|
||||
default="no",
|
||||
required=True,
|
||||
)
|
||||
manual_purchase_line_ids = fields.One2many(
|
||||
comodel_name='purchase.order.line',
|
||||
inverse_name='rma_line_id',
|
||||
string='Manual Purchase Order Lines',
|
||||
readonly=True, copy=False)
|
||||
comodel_name="purchase.order.line",
|
||||
inverse_name="rma_line_id",
|
||||
string="Manual Purchase Order Lines",
|
||||
readonly=True,
|
||||
copy=False,
|
||||
)
|
||||
qty_to_purchase = fields.Float(
|
||||
string='Qty To Purchase', copy=False,
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
readonly=True, compute='_compute_qty_purchase'
|
||||
string="Qty To Purchase",
|
||||
copy=False,
|
||||
digits=dp.get_precision("Product Unit of Measure"),
|
||||
readonly=True,
|
||||
compute="_compute_qty_purchase",
|
||||
)
|
||||
qty_purchased = fields.Float(
|
||||
string='Qty Purchased', copy=False,
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
readonly=True, compute='_compute_qty_purchase'
|
||||
string="Qty Purchased",
|
||||
copy=False,
|
||||
digits=dp.get_precision("Product Unit of Measure"),
|
||||
readonly=True,
|
||||
compute="_compute_qty_purchase",
|
||||
)
|
||||
|
||||
@api.onchange('product_id', 'partner_id')
|
||||
@api.onchange("product_id", "partner_id")
|
||||
def _onchange_product_id(self):
|
||||
"""Domain for purchase_order_line_id is computed here to make
|
||||
it dynamic."""
|
||||
res = super(RmaOrderLine, self)._onchange_product_id()
|
||||
if not res.get('domain'):
|
||||
res['domain'] = {}
|
||||
if not res.get("domain"):
|
||||
res["domain"] = {}
|
||||
domain = [
|
||||
'|',
|
||||
('order_id.partner_id', '=', self.partner_id.id),
|
||||
('order_id.partner_id', 'child_of', self.partner_id.id)]
|
||||
"|",
|
||||
("order_id.partner_id", "=", self.partner_id.id),
|
||||
("order_id.partner_id", "child_of", self.partner_id.id),
|
||||
]
|
||||
if self.product_id:
|
||||
domain.append(('product_id', '=', self.product_id.id))
|
||||
res['domain']['purchase_order_line_id'] = domain
|
||||
domain.append(("product_id", "=", self.product_id.id))
|
||||
res["domain"]["purchase_order_line_id"] = domain
|
||||
return res
|
||||
|
||||
@api.onchange('operation_id')
|
||||
@api.onchange("operation_id")
|
||||
def _onchange_operation_id(self):
|
||||
res = super(RmaOrderLine, self)._onchange_operation_id()
|
||||
if self.operation_id:
|
||||
self.purchase_policy = self.operation_id.purchase_policy or 'no'
|
||||
self.purchase_policy = self.operation_id.purchase_policy or "no"
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
@@ -106,98 +123,115 @@ class RmaOrderLine(models.Model):
|
||||
self.ensure_one()
|
||||
if not self.type:
|
||||
self.type = self._get_default_type()
|
||||
if self.type == 'customer':
|
||||
operation = line.product_id.rma_customer_operation_id or \
|
||||
line.product_id.categ_id.rma_customer_operation_id
|
||||
if self.type == "customer":
|
||||
operation = (
|
||||
line.product_id.rma_customer_operation_id
|
||||
or line.product_id.categ_id.rma_customer_operation_id
|
||||
)
|
||||
else:
|
||||
operation = line.product_id.rma_supplier_operation_id or \
|
||||
line.product_id.categ_id.rma_supplier_operation_id
|
||||
operation = (
|
||||
line.product_id.rma_supplier_operation_id
|
||||
or line.product_id.categ_id.rma_supplier_operation_id
|
||||
)
|
||||
if not operation:
|
||||
operation = self.env['rma.operation'].search(
|
||||
[('type', '=', self.type)], limit=1)
|
||||
operation = self.env["rma.operation"].search(
|
||||
[("type", "=", self.type)], limit=1
|
||||
)
|
||||
if not operation:
|
||||
raise ValidationError(_("Please define an operation first"))
|
||||
|
||||
if not operation.in_route_id or not operation.out_route_id:
|
||||
route = self.env['stock.location.route'].search(
|
||||
[('rma_selectable', '=', True)], limit=1)
|
||||
route = self.env["stock.location.route"].search(
|
||||
[("rma_selectable", "=", True)], limit=1
|
||||
)
|
||||
if not route:
|
||||
raise ValidationError(_("Please define a rma route."))
|
||||
|
||||
if not operation.in_warehouse_id or not operation.out_warehouse_id:
|
||||
warehouse = self.env['stock.warehouse'].search(
|
||||
[('company_id', '=', self.company_id.id),
|
||||
('lot_rma_id', '!=', False)], limit=1)
|
||||
warehouse = self.env["stock.warehouse"].search(
|
||||
[("company_id", "=", self.company_id.id), ("lot_rma_id", "!=", False)],
|
||||
limit=1,
|
||||
)
|
||||
if not warehouse:
|
||||
raise ValidationError(_(
|
||||
"Please define a warehouse with a default rma location."))
|
||||
raise ValidationError(
|
||||
_("Please define a warehouse with a default rma location.")
|
||||
)
|
||||
|
||||
data = {
|
||||
'product_id': line.product_id.id,
|
||||
'origin': line.order_id.name,
|
||||
'uom_id': line.product_uom.id,
|
||||
'operation_id': operation.id,
|
||||
'product_qty': line.product_qty,
|
||||
'price_unit': line.currency_id._convert(
|
||||
line.price_unit, line.currency_id,
|
||||
self.env.user.company_id, fields.Date.today(), round=False),
|
||||
'in_route_id': operation.in_route_id.id or route,
|
||||
'out_route_id': operation.out_route_id.id or route,
|
||||
'receipt_policy': operation.receipt_policy,
|
||||
'currency_id': line.currency_id.id,
|
||||
'location_id': (operation.location_id.id or
|
||||
operation.in_warehouse_id.lot_rma_id.id or
|
||||
warehouse.lot_rma_id.id),
|
||||
'refund_policy': operation.refund_policy,
|
||||
'delivery_policy': operation.delivery_policy,
|
||||
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
|
||||
'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id,
|
||||
"product_id": line.product_id.id,
|
||||
"origin": line.order_id.name,
|
||||
"uom_id": line.product_uom.id,
|
||||
"operation_id": operation.id,
|
||||
"product_qty": line.product_qty,
|
||||
"price_unit": line.currency_id._convert(
|
||||
line.price_unit,
|
||||
line.currency_id,
|
||||
self.env.user.company_id,
|
||||
fields.Date.today(),
|
||||
round=False,
|
||||
),
|
||||
"in_route_id": operation.in_route_id.id or route,
|
||||
"out_route_id": operation.out_route_id.id or route,
|
||||
"receipt_policy": operation.receipt_policy,
|
||||
"currency_id": line.currency_id.id,
|
||||
"location_id": (
|
||||
operation.location_id.id
|
||||
or operation.in_warehouse_id.lot_rma_id.id
|
||||
or warehouse.lot_rma_id.id
|
||||
),
|
||||
"refund_policy": operation.refund_policy,
|
||||
"delivery_policy": operation.delivery_policy,
|
||||
"in_warehouse_id": operation.in_warehouse_id.id or warehouse.id,
|
||||
"out_warehouse_id": operation.out_warehouse_id.id or warehouse.id,
|
||||
}
|
||||
return data
|
||||
|
||||
@api.onchange('purchase_order_line_id')
|
||||
@api.onchange("purchase_order_line_id")
|
||||
def _onchange_purchase_order_line_id(self):
|
||||
if not self.purchase_order_line_id:
|
||||
return
|
||||
data = self._prepare_rma_line_from_po_line(
|
||||
self.purchase_order_line_id)
|
||||
data = self._prepare_rma_line_from_po_line(self.purchase_order_line_id)
|
||||
self.update(data)
|
||||
self._remove_other_data_origin('purchase_order_line_id')
|
||||
self._remove_other_data_origin("purchase_order_line_id")
|
||||
|
||||
@api.multi
|
||||
@api.constrains('purchase_order_line_id', 'partner_id')
|
||||
@api.constrains("purchase_order_line_id", "partner_id")
|
||||
def _check_purchase_partner(self):
|
||||
for rec in self:
|
||||
if (rec.purchase_order_line_id and
|
||||
rec.purchase_order_line_id.order_id.partner_id !=
|
||||
rec.partner_id):
|
||||
raise ValidationError(_(
|
||||
"RMA customer and originating purchase line customer "
|
||||
"doesn't match."))
|
||||
if (
|
||||
rec.purchase_order_line_id
|
||||
and rec.purchase_order_line_id.order_id.partner_id != rec.partner_id
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"RMA customer and originating purchase line customer "
|
||||
"doesn't match."
|
||||
)
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _remove_other_data_origin(self, exception):
|
||||
res = super(RmaOrderLine, self)._remove_other_data_origin(exception)
|
||||
if not exception == 'purchase_order_line_id':
|
||||
if not exception == "purchase_order_line_id":
|
||||
self.purchase_order_line_id = False
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def action_view_purchase_order(self):
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
action = self.env.ref("purchase.purchase_rfq")
|
||||
result = action.read()[0]
|
||||
orders = self.mapped('purchase_order_line_ids.order_id')
|
||||
result['domain'] = [('id', 'in', orders.ids)]
|
||||
orders = self.mapped("purchase_order_line_ids.order_id")
|
||||
result["domain"] = [("id", "in", orders.ids)]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def _get_rma_purchased_qty(self):
|
||||
self.ensure_one()
|
||||
qty = 0.0
|
||||
if self.type == 'customer':
|
||||
if self.type == "customer":
|
||||
return qty
|
||||
for line in self.purchase_order_line_ids.filtered(
|
||||
lambda p: p.state not in ('draft', 'sent', 'cancel')):
|
||||
qty += self.uom_id._compute_quantity(
|
||||
line.product_qty, line.product_uom)
|
||||
lambda p: p.state not in ("draft", "sent", "cancel")
|
||||
):
|
||||
qty += self.uom_id._compute_quantity(line.product_qty, line.product_uom)
|
||||
return qty
|
||||
|
||||
0
rma_purchase/security/ir.model.access.csv
Executable file → Normal file
0
rma_purchase/security/ir.model.access.csv
Executable file → Normal file
@@ -1,92 +1,96 @@
|
||||
# Copyright 2017-18 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo.tests import common
|
||||
from odoo.fields import Datetime
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestRmaPurchase(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestRmaPurchase, self).setUp()
|
||||
|
||||
self.rma_obj = self.env['rma.order']
|
||||
self.rma_line_obj = self.env['rma.order.line']
|
||||
self.rma_op_obj = self.env['rma.operation']
|
||||
self.rma_add_purchase_wiz = self.env['rma_add_purchase']
|
||||
self.po_obj = self.env['purchase.order']
|
||||
self.pol_obj = self.env['purchase.order.line']
|
||||
self.product_obj = self.env['product.product']
|
||||
self.partner_obj = self.env['res.partner']
|
||||
self.rma_obj = self.env["rma.order"]
|
||||
self.rma_line_obj = self.env["rma.order.line"]
|
||||
self.rma_op_obj = self.env["rma.operation"]
|
||||
self.rma_add_purchase_wiz = self.env["rma_add_purchase"]
|
||||
self.po_obj = self.env["purchase.order"]
|
||||
self.pol_obj = self.env["purchase.order.line"]
|
||||
self.product_obj = self.env["product.product"]
|
||||
self.partner_obj = self.env["res.partner"]
|
||||
|
||||
self.rma_route_cust = self.env.ref('rma.route_rma_customer')
|
||||
self.rma_route_cust = self.env.ref("rma.route_rma_customer")
|
||||
|
||||
# Create supplier
|
||||
supplier1 = self.partner_obj.create({'name': 'Supplier 1'})
|
||||
supplier1 = self.partner_obj.create({"name": "Supplier 1"})
|
||||
|
||||
# Create products
|
||||
self.product_1 = self.product_obj.create({
|
||||
'name': 'Test Product 1',
|
||||
'type': 'product',
|
||||
})
|
||||
self.product_2 = self.product_obj.create({
|
||||
'name': 'Test Product 2',
|
||||
'type': 'product',
|
||||
})
|
||||
self.product_1 = self.product_obj.create(
|
||||
{"name": "Test Product 1", "type": "product"}
|
||||
)
|
||||
self.product_2 = self.product_obj.create(
|
||||
{"name": "Test Product 2", "type": "product"}
|
||||
)
|
||||
|
||||
# Create PO:
|
||||
self.po = self.po_obj.create({
|
||||
'partner_id': supplier1.id,
|
||||
})
|
||||
self.pol_1 = self.pol_obj.create({
|
||||
'name': self.product_1.name,
|
||||
'order_id': self.po.id,
|
||||
'product_id': self.product_1.id,
|
||||
'product_qty': 20.0,
|
||||
'product_uom': self.product_1.uom_id.id,
|
||||
'price_unit': 100.0,
|
||||
'date_planned': Datetime.now(),
|
||||
})
|
||||
self.pol_2 = self.pol_obj.create({
|
||||
'name': self.product_2.name,
|
||||
'order_id': self.po.id,
|
||||
'product_id': self.product_2.id,
|
||||
'product_qty': 18.0,
|
||||
'product_uom': self.product_2.uom_id.id,
|
||||
'price_unit': 150.0,
|
||||
'date_planned': Datetime.now(),
|
||||
})
|
||||
self.po = self.po_obj.create({"partner_id": supplier1.id})
|
||||
self.pol_1 = self.pol_obj.create(
|
||||
{
|
||||
"name": self.product_1.name,
|
||||
"order_id": self.po.id,
|
||||
"product_id": self.product_1.id,
|
||||
"product_qty": 20.0,
|
||||
"product_uom": self.product_1.uom_id.id,
|
||||
"price_unit": 100.0,
|
||||
"date_planned": Datetime.now(),
|
||||
}
|
||||
)
|
||||
self.pol_2 = self.pol_obj.create(
|
||||
{
|
||||
"name": self.product_2.name,
|
||||
"order_id": self.po.id,
|
||||
"product_id": self.product_2.id,
|
||||
"product_qty": 18.0,
|
||||
"product_uom": self.product_2.uom_id.id,
|
||||
"price_unit": 150.0,
|
||||
"date_planned": Datetime.now(),
|
||||
}
|
||||
)
|
||||
|
||||
# Create RMA group:
|
||||
self.rma_group = self.rma_obj.create({
|
||||
'partner_id': supplier1.id,
|
||||
'type': 'supplier',
|
||||
})
|
||||
self.rma_group = self.rma_obj.create(
|
||||
{"partner_id": supplier1.id, "type": "supplier"}
|
||||
)
|
||||
|
||||
def test_01_add_from_purchase_order(self):
|
||||
"""Test wizard to create supplier RMA from Purchase Orders."""
|
||||
self.assertEqual(self.rma_group.origin_po_count, 0)
|
||||
add_purchase = self.rma_add_purchase_wiz.with_context({
|
||||
'supplier': True,
|
||||
'active_ids': self.rma_group.id,
|
||||
'active_model': 'rma.order',
|
||||
}).create({
|
||||
'purchase_id': self.po.id,
|
||||
'purchase_line_ids': [(6, 0, self.po.order_line.ids)],
|
||||
})
|
||||
add_purchase = self.rma_add_purchase_wiz.with_context(
|
||||
{
|
||||
"supplier": True,
|
||||
"active_ids": self.rma_group.id,
|
||||
"active_model": "rma.order",
|
||||
}
|
||||
).create(
|
||||
{
|
||||
"purchase_id": self.po.id,
|
||||
"purchase_line_ids": [(6, 0, self.po.order_line.ids)],
|
||||
}
|
||||
)
|
||||
add_purchase.add_lines()
|
||||
self.assertEqual(len(self.rma_group.rma_line_ids), 2)
|
||||
for t in self.rma_group.rma_line_ids.mapped('type'):
|
||||
self.assertEqual(t, 'supplier')
|
||||
for t in self.rma_group.rma_line_ids.mapped("type"):
|
||||
self.assertEqual(t, "supplier")
|
||||
self.assertEqual(self.rma_group.origin_po_count, 1)
|
||||
|
||||
def test_02_fill_rma_from_po_line(self):
|
||||
"""Test filling a RMA (line) from a Purchase Order line."""
|
||||
rma = self.rma_line_obj.new({
|
||||
'partner_id': self.po.partner_id.id,
|
||||
'purchase_order_line_id': self.pol_1.id,
|
||||
'type': 'supplier',
|
||||
})
|
||||
rma = self.rma_line_obj.new(
|
||||
{
|
||||
"partner_id": self.po.partner_id.id,
|
||||
"purchase_order_line_id": self.pol_1.id,
|
||||
"type": "supplier",
|
||||
}
|
||||
)
|
||||
self.assertFalse(rma.product_id)
|
||||
rma._onchange_purchase_order_line_id()
|
||||
self.assertEqual(rma.product_id, self.product_1)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" ?>
|
||||
<!-- Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
||||
<odoo>
|
||||
@@ -6,10 +6,10 @@
|
||||
<record id="rma_operation_tree" model="ir.ui.view">
|
||||
<field name="name">rma.operation.tree - rma_purchase</field>
|
||||
<field name="model">rma.operation</field>
|
||||
<field name="inherit_id" ref="rma.rma_operation_tree"/>
|
||||
<field name="inherit_id" ref="rma.rma_operation_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="delivery_policy" position="after">
|
||||
<field name="purchase_policy"/>
|
||||
<field name="purchase_policy" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
@@ -17,10 +17,10 @@
|
||||
<record id="rma_operation_form" model="ir.ui.view">
|
||||
<field name="name">rma.operation.form - rma_purchase</field>
|
||||
<field name="model">rma.operation</field>
|
||||
<field name="inherit_id" ref="rma.rma_operation_form"/>
|
||||
<field name="inherit_id" ref="rma.rma_operation_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="delivery_policy" position="after">
|
||||
<field name="purchase_policy"/>
|
||||
<field name="purchase_policy" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="action_rma_line_purchase" model="ir.actions.act_window">
|
||||
@@ -12,13 +12,17 @@
|
||||
<record id="view_rma_line_supplier_button_sale_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.line.supplier.form</field>
|
||||
<field name="model">rma.order.line</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_line_supplier_button_form"/>
|
||||
<field name="inherit_id" ref="rma.view_rma_line_supplier_button_form" />
|
||||
<field name="arch" type="xml">
|
||||
<header position="inside">
|
||||
<button name="%(action_rma_order_line_make_purchase_order)d" states="approved"
|
||||
string="Create Purchase Order" class="oe_highlight"
|
||||
context="{'rma_line_id': active_id, 'default_partner_id': partner_id}"
|
||||
type="action"/>
|
||||
<button
|
||||
name="%(action_rma_order_line_make_purchase_order)d"
|
||||
states="approved"
|
||||
string="Create Purchase Order"
|
||||
class="oe_highlight"
|
||||
context="{'rma_line_id': active_id, 'default_partner_id': partner_id}"
|
||||
type="action"
|
||||
/>
|
||||
</header>
|
||||
</field>
|
||||
</record>
|
||||
@@ -26,41 +30,51 @@
|
||||
<record id="view_rma_line_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.line.supplier.form</field>
|
||||
<field name="model">rma.order.line</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_line_supplier_form"/>
|
||||
<field name="inherit_id" ref="rma.view_rma_line_supplier_form" />
|
||||
<field name="arch" type="xml">
|
||||
<div name='button_box' position="inside">
|
||||
<button type="object" name="action_view_purchase_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-shopping-cart"
|
||||
groups="purchase.group_purchase_user">
|
||||
<field name="purchase_count" widget="statinfo"
|
||||
string="Purchase Orders"/>
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_purchase_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-shopping-cart"
|
||||
groups="purchase.group_purchase_user"
|
||||
>
|
||||
<field
|
||||
name="purchase_count"
|
||||
widget="statinfo"
|
||||
string="Purchase Orders"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
<group name="main_info" position="inside">
|
||||
<field name="purchase_order_line_id"
|
||||
options="{'no_create': True}"
|
||||
context="{'rma': True}"
|
||||
domain="['|',
|
||||
<field
|
||||
name="purchase_order_line_id"
|
||||
options="{'no_create': True}"
|
||||
context="{'rma': True}"
|
||||
domain="['|',
|
||||
('order_id.partner_id', '=', partner_id),
|
||||
('order_id.partner_id', 'child_of', partner_id)]"/>
|
||||
('order_id.partner_id', 'child_of', partner_id)]"
|
||||
/>
|
||||
</group>
|
||||
<group name="quantities" position="inside">
|
||||
<group>
|
||||
<field name="qty_to_purchase"/>
|
||||
<field name="qty_purchased"/>
|
||||
<field name="qty_to_purchase" />
|
||||
<field name="qty_purchased" />
|
||||
</group>
|
||||
</group>
|
||||
<field name="delivery_policy" position="after">
|
||||
<field name="purchase_policy"/>
|
||||
<field name="purchase_policy" />
|
||||
</field>
|
||||
<field name="origin" position="after">
|
||||
<field name="purchase_id"
|
||||
attrs="{'invisible': [('purchase_order_line_id', '=', False)]}"/>
|
||||
<field
|
||||
name="purchase_id"
|
||||
attrs="{'invisible': [('purchase_order_line_id', '=', False)]}"
|
||||
/>
|
||||
</field>
|
||||
<notebook position="inside">
|
||||
<page name="purchase" string="Purchase Lines">
|
||||
<field name="purchase_order_line_ids" nolabel="1"/>
|
||||
<field name="purchase_order_line_ids" nolabel="1" />
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
|
||||
@@ -1,26 +1,37 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_rma_supplier_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.supplier.form</field>
|
||||
<field name="model">rma.order</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_supplier_form"/>
|
||||
<field name="inherit_id" ref="rma.view_rma_supplier_form" />
|
||||
<field name="arch" type="xml">
|
||||
<div name='button_box' position="inside">
|
||||
<button type="object" name="action_view_purchase_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-shopping-cart"
|
||||
groups="purchase.group_purchase_user">
|
||||
<field name="po_count" widget="statinfo"
|
||||
string="Purchase Orders"/>
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_purchase_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-shopping-cart"
|
||||
groups="purchase.group_purchase_user"
|
||||
>
|
||||
<field
|
||||
name="po_count"
|
||||
widget="statinfo"
|
||||
string="Purchase Orders"
|
||||
/>
|
||||
</button>
|
||||
<button type="object"
|
||||
name="action_view_origin_purchase_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-shopping-cart"
|
||||
groups="purchase.group_purchase_user">
|
||||
<field name="origin_po_count" widget="statinfo"
|
||||
string="Origin PO"/>
|
||||
<button
|
||||
type="object"
|
||||
name="action_view_origin_purchase_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-shopping-cart"
|
||||
groups="purchase.group_purchase_user"
|
||||
>
|
||||
<field
|
||||
name="origin_po_count"
|
||||
widget="statinfo"
|
||||
string="Origin PO"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
|
||||
@@ -6,91 +6,112 @@ from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RmaAddPurchase(models.TransientModel):
|
||||
_name = 'rma_add_purchase'
|
||||
_description = 'Wizard to add rma lines'
|
||||
_name = "rma_add_purchase"
|
||||
_description = "Wizard to add rma lines"
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super(RmaAddPurchase, self).default_get(fields_list)
|
||||
rma_obj = self.env['rma.order']
|
||||
rma_id = self.env.context['active_ids'] or []
|
||||
active_model = self.env.context['active_model']
|
||||
rma_obj = self.env["rma.order"]
|
||||
rma_id = self.env.context["active_ids"] or []
|
||||
active_model = self.env.context["active_model"]
|
||||
if not rma_id:
|
||||
return res
|
||||
assert active_model == 'rma.order', 'Bad context propagation'
|
||||
assert active_model == "rma.order", "Bad context propagation"
|
||||
|
||||
rma = rma_obj.browse(rma_id)
|
||||
res['rma_id'] = rma.id
|
||||
res['partner_id'] = rma.partner_id.id
|
||||
res['purchase_id'] = False
|
||||
res['purchase_line_ids'] = False
|
||||
res["rma_id"] = rma.id
|
||||
res["partner_id"] = rma.partner_id.id
|
||||
res["purchase_id"] = False
|
||||
res["purchase_line_ids"] = False
|
||||
return res
|
||||
|
||||
rma_id = fields.Many2one(
|
||||
comodel_name='rma.order', string='RMA Order', readonly=True)
|
||||
comodel_name="rma.order", string="RMA Order", readonly=True
|
||||
)
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner', string='Partner', readonly=True)
|
||||
purchase_id = fields.Many2one(
|
||||
comodel_name='purchase.order', string='Order')
|
||||
comodel_name="res.partner", string="Partner", readonly=True
|
||||
)
|
||||
purchase_id = fields.Many2one(comodel_name="purchase.order", string="Order")
|
||||
purchase_line_ids = fields.Many2many(
|
||||
comodel_name='purchase.order.line',
|
||||
relation='rma_add_purchase_add_line_rel',
|
||||
column1='rma_add_purchase_id', column2='purchase_line_id',
|
||||
readonly=False, string='Purchase Order Lines')
|
||||
comodel_name="purchase.order.line",
|
||||
relation="rma_add_purchase_add_line_rel",
|
||||
column1="rma_add_purchase_id",
|
||||
column2="purchase_line_id",
|
||||
readonly=False,
|
||||
string="Purchase Order Lines",
|
||||
)
|
||||
|
||||
def _prepare_rma_line_from_po_line(self, line):
|
||||
if self.env.context.get('customer'):
|
||||
operation = line.product_id.rma_customer_operation_id or \
|
||||
line.product_id.categ_id.rma_customer_operation_id
|
||||
if self.env.context.get("customer"):
|
||||
operation = (
|
||||
line.product_id.rma_customer_operation_id
|
||||
or line.product_id.categ_id.rma_customer_operation_id
|
||||
)
|
||||
else:
|
||||
operation = line.product_id.rma_supplier_operation_id or \
|
||||
line.product_id.categ_id.rma_supplier_operation_id
|
||||
operation = (
|
||||
line.product_id.rma_supplier_operation_id
|
||||
or line.product_id.categ_id.rma_supplier_operation_id
|
||||
)
|
||||
if not operation:
|
||||
operation = self.env['rma.operation'].search(
|
||||
[('type', '=', self.rma_id.type)], limit=1)
|
||||
operation = self.env["rma.operation"].search(
|
||||
[("type", "=", self.rma_id.type)], limit=1
|
||||
)
|
||||
if not operation:
|
||||
raise ValidationError(_("Please define an operation first"))
|
||||
if not operation.in_route_id or not operation.out_route_id:
|
||||
route = self.env['stock.location.route'].search(
|
||||
[('rma_selectable', '=', True)], limit=1)
|
||||
route = self.env["stock.location.route"].search(
|
||||
[("rma_selectable", "=", True)], limit=1
|
||||
)
|
||||
if not route:
|
||||
raise ValidationError(_("Please define a rma route."))
|
||||
if not operation.in_warehouse_id or not operation.out_warehouse_id:
|
||||
warehouse = self.env['stock.warehouse'].search(
|
||||
[('company_id', '=', self.rma_id.company_id.id),
|
||||
('lot_rma_id', '!=', False)], limit=1)
|
||||
warehouse = self.env["stock.warehouse"].search(
|
||||
[
|
||||
("company_id", "=", self.rma_id.company_id.id),
|
||||
("lot_rma_id", "!=", False),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if not warehouse:
|
||||
raise ValidationError(_("Please define a warehouse with a "
|
||||
"default rma location."))
|
||||
raise ValidationError(
|
||||
_("Please define a warehouse with a " "default rma location.")
|
||||
)
|
||||
data = {
|
||||
'partner_id': self.partner_id.id,
|
||||
'purchase_order_line_id': line.id,
|
||||
'product_id': line.product_id.id,
|
||||
'origin': line.order_id.name,
|
||||
'uom_id': line.product_uom.id,
|
||||
'operation_id': operation.id,
|
||||
'product_qty': line.product_qty,
|
||||
'price_unit': line.currency_id._convert(
|
||||
line.price_unit, line.currency_id,
|
||||
self.env.user.company_id, fields.Date.today(), round=False),
|
||||
'rma_id': self.rma_id.id,
|
||||
'in_route_id': operation.in_route_id.id or route,
|
||||
'out_route_id': operation.out_route_id.id or route,
|
||||
'receipt_policy': operation.receipt_policy,
|
||||
'location_id': (operation.location_id.id or
|
||||
operation.in_warehouse_id.lot_rma_id.id or
|
||||
warehouse.lot_rma_id.id),
|
||||
'refund_policy': operation.refund_policy,
|
||||
'delivery_policy': operation.delivery_policy,
|
||||
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
|
||||
'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id,
|
||||
"partner_id": self.partner_id.id,
|
||||
"purchase_order_line_id": line.id,
|
||||
"product_id": line.product_id.id,
|
||||
"origin": line.order_id.name,
|
||||
"uom_id": line.product_uom.id,
|
||||
"operation_id": operation.id,
|
||||
"product_qty": line.product_qty,
|
||||
"price_unit": line.currency_id._convert(
|
||||
line.price_unit,
|
||||
line.currency_id,
|
||||
self.env.user.company_id,
|
||||
fields.Date.today(),
|
||||
round=False,
|
||||
),
|
||||
"rma_id": self.rma_id.id,
|
||||
"in_route_id": operation.in_route_id.id or route,
|
||||
"out_route_id": operation.out_route_id.id or route,
|
||||
"receipt_policy": operation.receipt_policy,
|
||||
"location_id": (
|
||||
operation.location_id.id
|
||||
or operation.in_warehouse_id.lot_rma_id.id
|
||||
or warehouse.lot_rma_id.id
|
||||
),
|
||||
"refund_policy": operation.refund_policy,
|
||||
"delivery_policy": operation.delivery_policy,
|
||||
"in_warehouse_id": operation.in_warehouse_id.id or warehouse.id,
|
||||
"out_warehouse_id": operation.out_warehouse_id.id or warehouse.id,
|
||||
}
|
||||
return data
|
||||
|
||||
@api.model
|
||||
def _get_rma_data(self):
|
||||
data = {
|
||||
'date_rma': fields.Datetime.now(),
|
||||
"date_rma": fields.Datetime.now(),
|
||||
}
|
||||
return data
|
||||
|
||||
@@ -103,7 +124,7 @@ class RmaAddPurchase(models.TransientModel):
|
||||
|
||||
@api.multi
|
||||
def add_lines(self):
|
||||
rma_line_obj = self.env['rma.order.line']
|
||||
rma_line_obj = self.env["rma.order.line"]
|
||||
existing_purchase_lines = self._get_existing_purchase_lines()
|
||||
for line in self.purchase_line_ids:
|
||||
# Load a PO line only once
|
||||
@@ -113,4 +134,4 @@ class RmaAddPurchase(models.TransientModel):
|
||||
rma = self.rma_id
|
||||
data_rma = self._get_rma_data()
|
||||
rma.write(data_rma)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
return {"type": "ir.actions.act_window_close"}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<?xml version="1.0" ?>
|
||||
<odoo>
|
||||
<record id="view_rma_add_purchase" model="ir.ui.view">
|
||||
<field name="name">rma.add.purchase</field>
|
||||
@@ -7,41 +6,53 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select Purchase Order from customer">
|
||||
<group>
|
||||
<field name="partner_id"
|
||||
domain="[('customer','=',True)]"
|
||||
string="Customer"/>
|
||||
<field
|
||||
name="partner_id"
|
||||
domain="[('customer','=',True)]"
|
||||
string="Customer"
|
||||
/>
|
||||
</group>
|
||||
<separator string="Select Purchase Order from customer"/>
|
||||
<separator string="Select Purchase Order from customer" />
|
||||
<group>
|
||||
<field name="purchase_id"
|
||||
domain="[
|
||||
<field
|
||||
name="purchase_id"
|
||||
domain="[
|
||||
('partner_id','=',partner_id), (('state','not in',['draft','cancel']))]"
|
||||
context="{'partner_id': partner_id}"/>
|
||||
context="{'partner_id': partner_id}"
|
||||
/>
|
||||
</group>
|
||||
<separator string="Select Purchase Order Lines to Add"/>
|
||||
<field name="purchase_line_ids"
|
||||
domain="[('order_id', '=', purchase_id)]"
|
||||
string="Purchase Order Lines">
|
||||
<separator string="Select Purchase Order Lines to Add" />
|
||||
<field
|
||||
name="purchase_line_ids"
|
||||
domain="[('order_id', '=', purchase_id)]"
|
||||
string="Purchase Order Lines"
|
||||
>
|
||||
<tree string="Purchase Order Lines">
|
||||
<field name="order_id"/>
|
||||
<field name="name"/>
|
||||
<field name="order_id" />
|
||||
<field name="name" />
|
||||
<field name="partner_id" string="Vendor" />
|
||||
<field name="product_id"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom" groups="uom.group_uom"/>
|
||||
<field name="price_subtotal" widget="monetary"/>
|
||||
<field name="date_planned" widget="date"/>
|
||||
<field name="product_id" />
|
||||
<field name="price_unit" />
|
||||
<field name="product_qty" />
|
||||
<field name="product_uom" groups="uom.group_uom" />
|
||||
<field name="price_subtotal" widget="monetary" />
|
||||
<field name="date_planned" widget="date" />
|
||||
</tree>
|
||||
</field>
|
||||
<footer>
|
||||
<button
|
||||
string="Confirm"
|
||||
name="add_lines" type="object"
|
||||
class="oe_highlight"/>
|
||||
string="Confirm"
|
||||
name="add_lines"
|
||||
type="object"
|
||||
class="oe_highlight"
|
||||
/>
|
||||
or
|
||||
<button name="action_cancel"
|
||||
string="Cancel" class="oe_link" special="cancel"/>
|
||||
<button
|
||||
name="action_cancel"
|
||||
string="Cancel"
|
||||
class="oe_link"
|
||||
special="cancel"
|
||||
/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
@@ -55,19 +66,24 @@
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="view_rma_add_purchase"/>
|
||||
<field name="groups_id" eval="[(4, ref('rma.group_rma_customer_user')), (4, ref('rma.group_rma_customer_user'))]"/>
|
||||
<field name="view_id" ref="view_rma_add_purchase" />
|
||||
<field
|
||||
name="groups_id"
|
||||
eval="[(4, ref('rma.group_rma_customer_user')), (4, ref('rma.group_rma_customer_user'))]"
|
||||
/>
|
||||
</record>
|
||||
|
||||
<record id="view_rma_add_purchase_button_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.line.supplier.form</field>
|
||||
<field name="model">rma.order</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_supplier_form"/>
|
||||
<field name="inherit_id" ref="rma.view_rma_supplier_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//header" position="inside">
|
||||
<button name="%(action_rma_add_purchase)d"
|
||||
string="Add From Purchase Order"
|
||||
type="action"/>
|
||||
<button
|
||||
name="%(action_rma_add_purchase)d"
|
||||
string="Add From Purchase Order"
|
||||
type="action"
|
||||
/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -5,34 +5,33 @@ from odoo import api, fields, models
|
||||
|
||||
|
||||
class RmaMakePicking(models.TransientModel):
|
||||
_inherit = 'rma_make_picking.wizard'
|
||||
_inherit = "rma_make_picking.wizard"
|
||||
|
||||
@api.returns('rma.order.line')
|
||||
@api.returns("rma.order.line")
|
||||
def _prepare_item(self, line):
|
||||
res = super(RmaMakePicking, self)._prepare_item(line)
|
||||
res['purchase_order_line_id'] = line.purchase_order_line_id.id
|
||||
res["purchase_order_line_id"] = line.purchase_order_line_id.id
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _get_action(self, pickings, procurements):
|
||||
po_list = []
|
||||
for procurement in procurements:
|
||||
if procurement.purchase_id and \
|
||||
procurement.purchase_id.id:
|
||||
if procurement.purchase_id and procurement.purchase_id.id:
|
||||
po_list.append(procurement.purchase_id.id)
|
||||
if len(po_list):
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
action = self.env.ref("purchase.purchase_rfq")
|
||||
result = action.read()[0]
|
||||
result['domain'] = [('id', 'in', po_list)]
|
||||
result["domain"] = [("id", "in", po_list)]
|
||||
return result
|
||||
else:
|
||||
action = super(RmaMakePicking, self)._get_action(pickings,
|
||||
procurements)
|
||||
action = super(RmaMakePicking, self)._get_action(pickings, procurements)
|
||||
return action
|
||||
|
||||
|
||||
class RmaMakePickingItem(models.TransientModel):
|
||||
_inherit = "rma_make_picking.wizard.item"
|
||||
|
||||
purchase_order_line_id = fields.Many2one('purchase.order.line',
|
||||
string='Purchase Line')
|
||||
purchase_order_line_id = fields.Many2one(
|
||||
"purchase.order.line", string="Purchase Line"
|
||||
)
|
||||
|
||||
@@ -1,74 +1,86 @@
|
||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
|
||||
|
||||
import odoo.addons.decimal_precision as dp
|
||||
from odoo import fields, models, api, _, exceptions
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT as DF
|
||||
from datetime import datetime
|
||||
|
||||
from odoo import _, api, exceptions, fields, models
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT as DF
|
||||
|
||||
import odoo.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class RmaLineMakePurchaseOrder(models.TransientModel):
|
||||
_name = "rma.order.line.make.purchase.order"
|
||||
_description = "Make Purchases Order from RMA Line"
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner', string='Supplier', required=False,
|
||||
domain=[('supplier', '=', True)], readonly=1)
|
||||
comodel_name="res.partner",
|
||||
string="Supplier",
|
||||
required=False,
|
||||
domain=[("supplier", "=", True)],
|
||||
readonly=1,
|
||||
)
|
||||
item_ids = fields.One2many(
|
||||
comodel_name='rma.order.line.make.purchase.order.item',
|
||||
inverse_name='wiz_id', string='Items')
|
||||
comodel_name="rma.order.line.make.purchase.order.item",
|
||||
inverse_name="wiz_id",
|
||||
string="Items",
|
||||
)
|
||||
purchase_order_id = fields.Many2one(
|
||||
comodel_name='purchase.order', string='Purchases Order',
|
||||
required=False, domain=[('state', '=', 'draft')])
|
||||
comodel_name="purchase.order",
|
||||
string="Purchases Order",
|
||||
required=False,
|
||||
domain=[("state", "=", "draft")],
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _prepare_item(self, line):
|
||||
return {
|
||||
'line_id': line.id,
|
||||
'rma_line_id': line.id,
|
||||
'product_id': line.product_id.id,
|
||||
'name': line.product_id.name,
|
||||
'product_qty': line.qty_to_purchase,
|
||||
'rma_id': line.rma_id.id,
|
||||
'product_uom_id': line.uom_id.id,
|
||||
"line_id": line.id,
|
||||
"rma_line_id": line.id,
|
||||
"product_id": line.product_id.id,
|
||||
"name": line.product_id.name,
|
||||
"product_qty": line.qty_to_purchase,
|
||||
"rma_id": line.rma_id.id,
|
||||
"product_uom_id": line.uom_id.id,
|
||||
}
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super(RmaLineMakePurchaseOrder, self).default_get(
|
||||
fields_list)
|
||||
rma_line_obj = self.env['rma.order.line']
|
||||
rma_line_ids = self.env.context['active_ids'] or []
|
||||
active_model = self.env.context['active_model']
|
||||
res = super(RmaLineMakePurchaseOrder, self).default_get(fields_list)
|
||||
rma_line_obj = self.env["rma.order.line"]
|
||||
rma_line_ids = self.env.context["active_ids"] or []
|
||||
active_model = self.env.context["active_model"]
|
||||
|
||||
if not rma_line_ids:
|
||||
return res
|
||||
assert active_model == 'rma.order.line', 'Bad context propagation'
|
||||
assert active_model == "rma.order.line", "Bad context propagation"
|
||||
|
||||
items = []
|
||||
lines = rma_line_obj.browse(rma_line_ids)
|
||||
for line in lines:
|
||||
items.append([0, 0, self._prepare_item(line)])
|
||||
suppliers = lines.mapped('partner_id')
|
||||
suppliers = lines.mapped("partner_id")
|
||||
if len(suppliers) == 1:
|
||||
res['partner_id'] = suppliers.id
|
||||
res["partner_id"] = suppliers.id
|
||||
else:
|
||||
raise exceptions.Warning(
|
||||
_('Only RMA lines from the same partner can be processed at '
|
||||
'the same time'))
|
||||
res['item_ids'] = items
|
||||
_(
|
||||
"Only RMA lines from the same partner can be processed at "
|
||||
"the same time"
|
||||
)
|
||||
)
|
||||
res["item_ids"] = items
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _prepare_purchase_order(self, item):
|
||||
if not self.partner_id:
|
||||
raise exceptions.Warning(
|
||||
_('Enter a supplier.'))
|
||||
raise exceptions.Warning(_("Enter a supplier."))
|
||||
supplier = self.partner_id
|
||||
data = {
|
||||
'origin': '',
|
||||
'partner_id': supplier.id,
|
||||
'company_id': item.line_id.company_id.id,
|
||||
"origin": "",
|
||||
"partner_id": supplier.id,
|
||||
"company_id": item.line_id.company_id.id,
|
||||
}
|
||||
return data
|
||||
|
||||
@@ -76,29 +88,28 @@ class RmaLineMakePurchaseOrder(models.TransientModel):
|
||||
def _prepare_purchase_order_line(self, po, item):
|
||||
product = item.product_id
|
||||
vals = {
|
||||
'name': product.name,
|
||||
'order_id': po.id,
|
||||
'product_id': product.id,
|
||||
'price_unit': item.line_id.price_unit,
|
||||
'date_planned': datetime.today().strftime(DF),
|
||||
'product_uom': product.uom_po_id.id,
|
||||
'product_qty': item.product_qty,
|
||||
'rma_line_id': item.line_id.id
|
||||
"name": product.name,
|
||||
"order_id": po.id,
|
||||
"product_id": product.id,
|
||||
"price_unit": item.line_id.price_unit,
|
||||
"date_planned": datetime.today().strftime(DF),
|
||||
"product_uom": product.uom_po_id.id,
|
||||
"product_qty": item.product_qty,
|
||||
"rma_line_id": item.line_id.id,
|
||||
}
|
||||
if item.free_of_charge:
|
||||
vals['price_unit'] = 0.0
|
||||
vals["price_unit"] = 0.0
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def create_purchase_order(self):
|
||||
res = []
|
||||
purchase_obj = self.env['purchase.order']
|
||||
po_line_obj = self.env['purchase.order.line']
|
||||
purchase_obj = self.env["purchase.order"]
|
||||
po_line_obj = self.env["purchase.order.line"]
|
||||
|
||||
for item in self.item_ids:
|
||||
if item.product_qty <= 0.0:
|
||||
raise exceptions.Warning(
|
||||
_('Enter a positive quantity.'))
|
||||
raise exceptions.Warning(_("Enter a positive quantity."))
|
||||
|
||||
purchase = self.purchase_order_id
|
||||
if not purchase:
|
||||
@@ -109,9 +120,9 @@ class RmaLineMakePurchaseOrder(models.TransientModel):
|
||||
po_line_obj.create(po_line_data)
|
||||
res.append(purchase.id)
|
||||
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
action = self.env.ref("purchase.purchase_rfq")
|
||||
result = action.read()[0]
|
||||
result['domain'] = "[('id','in', ["+','.join(map(str, res))+"])]"
|
||||
result["domain"] = "[('id','in', [" + ",".join(map(str, res)) + "])]"
|
||||
return result
|
||||
|
||||
|
||||
@@ -120,18 +131,17 @@ class RmaLineMakePurchaseOrderItem(models.TransientModel):
|
||||
_description = "RMA Line Make Purchase Order Item"
|
||||
|
||||
wiz_id = fields.Many2one(
|
||||
comodel_name='rma.order.line.make.purchase.order', string='Wizard')
|
||||
line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA Line')
|
||||
comodel_name="rma.order.line.make.purchase.order", string="Wizard"
|
||||
)
|
||||
line_id = fields.Many2one(comodel_name="rma.order.line", string="RMA Line")
|
||||
rma_id = fields.Many2one(
|
||||
comodel_name='rma.order', related='line_id.rma_id',
|
||||
string='RMA Order')
|
||||
product_id = fields.Many2one(
|
||||
comodel_name='product.product', string='Product')
|
||||
name = fields.Char(string='Description')
|
||||
comodel_name="rma.order", related="line_id.rma_id", string="RMA Order"
|
||||
)
|
||||
product_id = fields.Many2one(comodel_name="product.product", string="Product")
|
||||
name = fields.Char(string="Description")
|
||||
product_qty = fields.Float(
|
||||
string='Quantity to purchase',
|
||||
digits=dp.get_precision('Product Unit of Measure'),)
|
||||
product_uom_id = fields.Many2one(
|
||||
comodel_name='uom.uom', string='UoM')
|
||||
free_of_charge = fields.Boolean(string='Free of Charge')
|
||||
string="Quantity to purchase",
|
||||
digits=dp.get_precision("Product Unit of Measure"),
|
||||
)
|
||||
product_uom_id = fields.Many2one(comodel_name="uom.uom", string="UoM")
|
||||
free_of_charge = fields.Boolean(string="Free of Charge")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" ?>
|
||||
<odoo>
|
||||
<record id="view_rma_order_line_make_purchase_order" model="ir.ui.view">
|
||||
<field name="name">RMA Line Make Purchase Order</field>
|
||||
@@ -6,56 +6,69 @@
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Create Quotation" create="false" edit="false">
|
||||
<separator string="Existing Quotation to update:"/>
|
||||
<newline/>
|
||||
<separator string="Existing Quotation to update:" />
|
||||
<newline />
|
||||
<group>
|
||||
<field name="purchase_order_id"
|
||||
<field
|
||||
name="purchase_order_id"
|
||||
domain="[('partner_id','=',partner_id)]"
|
||||
context="{'partner_id': partner_id}"/>
|
||||
context="{'partner_id': partner_id}"
|
||||
/>
|
||||
</group>
|
||||
<newline/>
|
||||
<separator
|
||||
string="New Purchases Order details:"/>
|
||||
<newline/>
|
||||
<newline />
|
||||
<separator string="New Purchases Order details:" />
|
||||
<newline />
|
||||
<group>
|
||||
<field name="partner_id"/>
|
||||
<field name="partner_id" />
|
||||
</group>
|
||||
<newline/>
|
||||
<newline />
|
||||
<group>
|
||||
<field name="item_ids" nolabel="1" colspan="2">
|
||||
<tree string="Details" editable="bottom" create="false">
|
||||
<field name="line_id"
|
||||
options="{'no_open': true}"/>
|
||||
<field name="product_id"/>
|
||||
<field name="name"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom_id"
|
||||
groups="uom.group_uom"/>
|
||||
<field name="free_of_charge"/>
|
||||
<tree
|
||||
string="Details"
|
||||
editable="bottom"
|
||||
create="false"
|
||||
>
|
||||
<field
|
||||
name="line_id"
|
||||
options="{'no_open': true}"
|
||||
/>
|
||||
<field name="product_id" />
|
||||
<field name="name" />
|
||||
<field name="product_qty" />
|
||||
<field
|
||||
name="product_uom_id"
|
||||
groups="uom.group_uom"
|
||||
/>
|
||||
<field name="free_of_charge" />
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<newline/>
|
||||
<newline />
|
||||
<footer colspan="2">
|
||||
<button name="create_purchase_order"
|
||||
string="Create RFQ" type="object"
|
||||
class="oe_highlight"/>
|
||||
<button special="cancel" string="Cancel" class="oe_link"/>
|
||||
<button
|
||||
name="create_purchase_order"
|
||||
string="Create RFQ"
|
||||
type="object"
|
||||
class="oe_highlight"
|
||||
/>
|
||||
<button special="cancel" string="Cancel" class="oe_link" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_rma_order_line_make_purchase_order"
|
||||
model="ir.actions.act_window">
|
||||
<record
|
||||
id="action_rma_order_line_make_purchase_order"
|
||||
model="ir.actions.act_window"
|
||||
>
|
||||
<field name="name">Create RFQ</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">rma.order.line.make.purchase.order</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_rma_order_line_make_purchase_order"/>
|
||||
<field name="view_id" ref="view_rma_order_line_make_purchase_order" />
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user