mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[IMP] rma: black, isort, prettier
This commit is contained in:
committed by
Pedro M. Baeza
parent
b3bcbbaf99
commit
15ee35246e
@@ -3,61 +3,52 @@
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
import odoo.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class RmaReDeliveryWizard(models.TransientModel):
|
||||
_name = 'rma.delivery.wizard'
|
||||
_description = 'RMA Delivery Wizard'
|
||||
_name = "rma.delivery.wizard"
|
||||
_description = "RMA Delivery Wizard"
|
||||
|
||||
rma_count = fields.Integer()
|
||||
type = fields.Selection(
|
||||
selection=[
|
||||
('replace', 'Replace'),
|
||||
('return', 'Return to customer'),
|
||||
],
|
||||
selection=[("replace", "Replace"), ("return", "Return to customer"),],
|
||||
string="Type",
|
||||
required=True,
|
||||
)
|
||||
product_id = fields.Many2one(
|
||||
comodel_name="product.product",
|
||||
string="Replace Product",
|
||||
comodel_name="product.product", string="Replace Product",
|
||||
)
|
||||
product_uom_qty = fields.Float(
|
||||
string='Product qty',
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
)
|
||||
product_uom = fields.Many2one(
|
||||
comodel_name="uom.uom",
|
||||
string="Unit of measure",
|
||||
)
|
||||
scheduled_date = fields.Datetime(
|
||||
required=True,
|
||||
default=fields.Datetime.now(),
|
||||
string="Product qty", digits=dp.get_precision("Product Unit of Measure"),
|
||||
)
|
||||
product_uom = fields.Many2one(comodel_name="uom.uom", string="Unit of measure",)
|
||||
scheduled_date = fields.Datetime(required=True, default=fields.Datetime.now(),)
|
||||
warehouse_id = fields.Many2one(
|
||||
comodel_name="stock.warehouse",
|
||||
string='Warehouse',
|
||||
required=True,
|
||||
comodel_name="stock.warehouse", string="Warehouse", required=True,
|
||||
)
|
||||
|
||||
@api.constrains('product_uom_qty')
|
||||
@api.constrains("product_uom_qty")
|
||||
def _check_product_uom_qty(self):
|
||||
self.ensure_one()
|
||||
rma_ids = self.env.context.get('active_ids')
|
||||
rma_ids = self.env.context.get("active_ids")
|
||||
if len(rma_ids) == 1 and self.product_uom_qty <= 0:
|
||||
raise ValidationError(_('Quantity must be greater than 0.'))
|
||||
raise ValidationError(_("Quantity must be greater than 0."))
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super().default_get(fields_list)
|
||||
rma_ids = self.env.context.get('active_ids')
|
||||
rma = self.env['rma'].browse(rma_ids)
|
||||
warehouse_id = self.env['stock.warehouse'].search(
|
||||
[('company_id', '=', rma[0].company_id.id)], limit=1).id
|
||||
delivery_type = self.env.context.get('rma_delivery_type')
|
||||
rma_ids = self.env.context.get("active_ids")
|
||||
rma = self.env["rma"].browse(rma_ids)
|
||||
warehouse_id = (
|
||||
self.env["stock.warehouse"]
|
||||
.search([("company_id", "=", rma[0].company_id.id)], limit=1)
|
||||
.id
|
||||
)
|
||||
delivery_type = self.env.context.get("rma_delivery_type")
|
||||
product_id = False
|
||||
if len(rma) == 1 and delivery_type == 'return':
|
||||
if len(rma) == 1 and delivery_type == "return":
|
||||
product_id = rma.product_id.id
|
||||
product_uom_qty = 0.0
|
||||
if len(rma) == 1 and rma.remaining_qty > 0.0:
|
||||
@@ -76,18 +67,17 @@ class RmaReDeliveryWizard(models.TransientModel):
|
||||
domain_product_uom = []
|
||||
if self.product_id:
|
||||
domain_product_uom = [
|
||||
('category_id', '=', self.product_id.uom_id.category_id.id)
|
||||
("category_id", "=", self.product_id.uom_id.category_id.id)
|
||||
]
|
||||
if (not self.product_uom
|
||||
or self.product_id.uom_id.id != self.product_uom.id):
|
||||
if not self.product_uom or self.product_id.uom_id.id != self.product_uom.id:
|
||||
self.product_uom = self.product_id.uom_id
|
||||
return {'domain': {'product_uom': domain_product_uom}}
|
||||
return {"domain": {"product_uom": domain_product_uom}}
|
||||
|
||||
def action_deliver(self):
|
||||
self.ensure_one()
|
||||
rma_ids = self.env.context.get('active_ids')
|
||||
rma = self.env['rma'].browse(rma_ids)
|
||||
if self.type == 'replace':
|
||||
rma_ids = self.env.context.get("active_ids")
|
||||
rma = self.env["rma"].browse(rma_ids)
|
||||
if self.type == "replace":
|
||||
rma.create_replace(
|
||||
self.scheduled_date,
|
||||
self.warehouse_id,
|
||||
@@ -95,7 +85,7 @@ class RmaReDeliveryWizard(models.TransientModel):
|
||||
self.product_uom_qty,
|
||||
self.product_uom,
|
||||
)
|
||||
elif self.type == 'return':
|
||||
elif self.type == "return":
|
||||
qty = uom = None
|
||||
if self.rma_count == 1:
|
||||
qty, uom = self.product_uom_qty, self.product_uom
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2020 Tecnativa - Ernesto Tejeda
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
@@ -9,42 +9,61 @@
|
||||
<form>
|
||||
<group>
|
||||
<group>
|
||||
<field name="scheduled_date"/>
|
||||
<field name="warehouse_id"
|
||||
attrs="{'invisible': [('type', '!=', 'replace')]}"/>
|
||||
<field name="scheduled_date" />
|
||||
<field
|
||||
name="warehouse_id"
|
||||
attrs="{'invisible': [('type', '!=', 'replace')]}"
|
||||
/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="product_id"
|
||||
attrs="{'invisible': ['|', ('type', '!=', 'replace'), ('rma_count', '>', 1)], 'required': [('type', '=', 'replace'), ('rma_count', '=', 1)]}"/>
|
||||
<label for="product_uom_qty"
|
||||
attrs="{'invisible': [('rma_count', '>', 1)]}"/>
|
||||
<div class="o_row"
|
||||
attrs="{'invisible': [('rma_count', '>', 1)]}">
|
||||
<field name="product_uom_qty"
|
||||
attrs="{'required': [('rma_count', '=', 1)]}"/>
|
||||
<field name="product_uom"
|
||||
groups="uom.group_uom"
|
||||
attrs="{'required': [('rma_count', '=', 1)]}"/>
|
||||
<field
|
||||
name="product_id"
|
||||
attrs="{'invisible': ['|', ('type', '!=', 'replace'), ('rma_count', '>', 1)], 'required': [('type', '=', 'replace'), ('rma_count', '=', 1)]}"
|
||||
/>
|
||||
<label
|
||||
for="product_uom_qty"
|
||||
attrs="{'invisible': [('rma_count', '>', 1)]}"
|
||||
/>
|
||||
<div
|
||||
class="o_row"
|
||||
attrs="{'invisible': [('rma_count', '>', 1)]}"
|
||||
>
|
||||
<field
|
||||
name="product_uom_qty"
|
||||
attrs="{'required': [('rma_count', '=', 1)]}"
|
||||
/>
|
||||
<field
|
||||
name="product_uom"
|
||||
groups="uom.group_uom"
|
||||
attrs="{'required': [('rma_count', '=', 1)]}"
|
||||
/>
|
||||
</div>
|
||||
</group>
|
||||
</group>
|
||||
<field name="rma_count" invisible="1"/>
|
||||
<field name="type" invisible="1"/>
|
||||
<field name="rma_count" invisible="1" />
|
||||
<field name="type" invisible="1" />
|
||||
<footer>
|
||||
<button name="action_deliver" string="Deliver" type="object" class="btn-primary"/>
|
||||
<button
|
||||
name="action_deliver"
|
||||
string="Deliver"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<act_window id="rma_delivery_wizard_action"
|
||||
name="Return to customer"
|
||||
src_model="rma"
|
||||
res_model="rma.delivery.wizard"
|
||||
view_type="form"
|
||||
view_mode="form"
|
||||
key2="client_action_multi"
|
||||
target="new"
|
||||
multi="True"
|
||||
context="{'rma_delivery_type': 'return'}"/>
|
||||
<act_window
|
||||
id="rma_delivery_wizard_action"
|
||||
name="Return to customer"
|
||||
src_model="rma"
|
||||
res_model="rma.delivery.wizard"
|
||||
view_type="form"
|
||||
view_mode="form"
|
||||
key2="client_action_multi"
|
||||
target="new"
|
||||
multi="True"
|
||||
context="{'rma_delivery_type': 'return'}"
|
||||
/>
|
||||
</odoo>
|
||||
|
||||
@@ -2,52 +2,48 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
import odoo.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class RmaReSplitWizard(models.TransientModel):
|
||||
_name = 'rma.split.wizard'
|
||||
_description = 'RMA Split Wizard'
|
||||
_name = "rma.split.wizard"
|
||||
_description = "RMA Split Wizard"
|
||||
|
||||
rma_id = fields.Many2one(
|
||||
comodel_name='rma',
|
||||
string='RMA',
|
||||
)
|
||||
rma_id = fields.Many2one(comodel_name="rma", string="RMA",)
|
||||
product_uom_qty = fields.Float(
|
||||
string='Quantity to extract',
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
string="Quantity to extract",
|
||||
digits=dp.get_precision("Product Unit of Measure"),
|
||||
required=True,
|
||||
help="Quantity to extract to a new RMA."
|
||||
help="Quantity to extract to a new RMA.",
|
||||
)
|
||||
product_uom = fields.Many2one(
|
||||
comodel_name='uom.uom',
|
||||
string='Unit of measure',
|
||||
required=True,
|
||||
comodel_name="uom.uom", string="Unit of measure", required=True,
|
||||
)
|
||||
|
||||
_sql_constraints = [
|
||||
(
|
||||
'check_product_uom_qty_positive',
|
||||
'CHECK(product_uom_qty > 0)',
|
||||
'Quantity must be greater than 0.'
|
||||
"check_product_uom_qty_positive",
|
||||
"CHECK(product_uom_qty > 0)",
|
||||
"Quantity must be greater than 0.",
|
||||
),
|
||||
]
|
||||
|
||||
@api.model
|
||||
def fields_get(self, allfields=None, attributes=None):
|
||||
res = super().fields_get(allfields, attributes=attributes)
|
||||
rma_id = self.env.context.get('active_id')
|
||||
rma = self.env['rma'].browse(rma_id)
|
||||
res['product_uom']['domain'] = [
|
||||
('category_id', '=', rma.product_uom.category_id.id)
|
||||
rma_id = self.env.context.get("active_id")
|
||||
rma = self.env["rma"].browse(rma_id)
|
||||
res["product_uom"]["domain"] = [
|
||||
("category_id", "=", rma.product_uom.category_id.id)
|
||||
]
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super().default_get(fields_list)
|
||||
rma_id = self.env.context.get('active_id')
|
||||
rma = self.env['rma'].browse(rma_id)
|
||||
rma_id = self.env.context.get("active_id")
|
||||
rma = self.env["rma"].browse(rma_id)
|
||||
res.update(
|
||||
rma_id=rma.id,
|
||||
product_uom_qty=rma.remaining_qty,
|
||||
@@ -58,13 +54,14 @@ class RmaReSplitWizard(models.TransientModel):
|
||||
def action_split(self):
|
||||
self.ensure_one()
|
||||
extracted_rma = self.rma_id.extract_quantity(
|
||||
self.product_uom_qty, self.product_uom)
|
||||
self.product_uom_qty, self.product_uom
|
||||
)
|
||||
return {
|
||||
'name': _('Extracted RMA'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'rma',
|
||||
'views': [(self.env.ref('rma.rma_view_form').id, 'form')],
|
||||
'res_id': extracted_rma.id,
|
||||
"name": _("Extracted RMA"),
|
||||
"type": "ir.actions.act_window",
|
||||
"view_type": "form",
|
||||
"view_mode": "form",
|
||||
"res_model": "rma",
|
||||
"views": [(self.env.ref("rma.rma_view_form").id, "form")],
|
||||
"res_id": extracted_rma.id,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2020 Tecnativa - Ernesto Tejeda
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
@@ -9,15 +9,20 @@
|
||||
<form>
|
||||
<group>
|
||||
<group>
|
||||
<label for="product_uom_qty"/>
|
||||
<label for="product_uom_qty" />
|
||||
<div class="o_row">
|
||||
<field name="product_uom_qty"/>
|
||||
<field name="product_uom" groups="uom.group_uom"/>
|
||||
<field name="product_uom_qty" />
|
||||
<field name="product_uom" groups="uom.group_uom" />
|
||||
</div>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_split" string="Split" type="object" class="btn-primary"/>
|
||||
<button
|
||||
name="action_split"
|
||||
string="Split"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
|
||||
@@ -6,18 +6,16 @@ from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ReturnPicking(models.TransientModel):
|
||||
_inherit = 'stock.return.picking'
|
||||
_inherit = "stock.return.picking"
|
||||
|
||||
create_rma = fields.Boolean(
|
||||
string="Create RMAs"
|
||||
)
|
||||
create_rma = fields.Boolean(string="Create RMAs")
|
||||
picking_type_code = fields.Selection(
|
||||
selection=[
|
||||
('incoming', 'Vendors'),
|
||||
('outgoing', 'Customers'),
|
||||
('internal', 'Internal'),
|
||||
("incoming", "Vendors"),
|
||||
("outgoing", "Customers"),
|
||||
("internal", "Internal"),
|
||||
],
|
||||
related='picking_id.picking_type_id.code',
|
||||
related="picking_id.picking_type_id.code",
|
||||
store=True,
|
||||
readonly=True,
|
||||
)
|
||||
@@ -27,16 +25,16 @@ class ReturnPicking(models.TransientModel):
|
||||
if self.create_rma:
|
||||
warehouse = self.picking_id.picking_type_id.warehouse_id
|
||||
self.location_id = warehouse.rma_loc_id.id
|
||||
rma_loc = warehouse.search([]).mapped('rma_loc_id')
|
||||
rma_loc_domain = [('id', 'child_of', rma_loc.ids)]
|
||||
rma_loc = warehouse.search([]).mapped("rma_loc_id")
|
||||
rma_loc_domain = [("id", "child_of", rma_loc.ids)]
|
||||
else:
|
||||
self.location_id = self.default_get(['location_id'])['location_id']
|
||||
self.location_id = self.default_get(["location_id"])["location_id"]
|
||||
rma_loc_domain = [
|
||||
'|',
|
||||
('id', '=', self.picking_id.location_id.id),
|
||||
('return_location', '=', True),
|
||||
"|",
|
||||
("id", "=", self.picking_id.location_id.id),
|
||||
("return_location", "=", True),
|
||||
]
|
||||
return {'domain': {'location_id': rma_loc_domain}}
|
||||
return {"domain": {"location_id": rma_loc_domain}}
|
||||
|
||||
def create_returns(self):
|
||||
""" Override create_returns method for creating one or more
|
||||
@@ -52,13 +50,18 @@ class ReturnPicking(models.TransientModel):
|
||||
self_with_context = self.with_context(set_rma_picking_type=True)
|
||||
res = super(ReturnPicking, self_with_context).create_returns()
|
||||
if not self.picking_id.partner_id:
|
||||
raise ValidationError(_(
|
||||
"You must specify the 'Customer' in the "
|
||||
"'Stock Picking' from which RMAs will be created"))
|
||||
returned_picking = self.env['stock.picking'].browse(res['res_id'])
|
||||
vals_list = [move._prepare_return_rma_vals(self.picking_id)
|
||||
for move in returned_picking.move_lines]
|
||||
self.env['rma'].create(vals_list)
|
||||
raise ValidationError(
|
||||
_(
|
||||
"You must specify the 'Customer' in the "
|
||||
"'Stock Picking' from which RMAs will be created"
|
||||
)
|
||||
)
|
||||
returned_picking = self.env["stock.picking"].browse(res["res_id"])
|
||||
vals_list = [
|
||||
move._prepare_return_rma_vals(self.picking_id)
|
||||
for move in returned_picking.move_lines
|
||||
]
|
||||
self.env["rma"].create(vals_list)
|
||||
return res
|
||||
else:
|
||||
return super().create_returns()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2020 Tecnativa - Ernesto Tejeda
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
@@ -7,12 +7,17 @@
|
||||
<field name="model">stock.return.picking</field>
|
||||
<field name="inherit_id" ref="stock.view_stock_return_picking_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[.//field[@name='product_return_moves']]" position="before">
|
||||
<xpath
|
||||
expr="//group[.//field[@name='product_return_moves']]"
|
||||
position="before"
|
||||
>
|
||||
<group name="group_rma">
|
||||
<field name="create_rma"
|
||||
attrs="{'invisible': [('picking_type_code', '!=', 'outgoing')]}"/>
|
||||
<field name="picking_id" invisible="1"/>
|
||||
<field name="picking_type_code" invisible="1"/>
|
||||
<field
|
||||
name="create_rma"
|
||||
attrs="{'invisible': [('picking_type_code', '!=', 'outgoing')]}"
|
||||
/>
|
||||
<field name="picking_id" invisible="1" />
|
||||
<field name="picking_type_code" invisible="1" />
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user