[MIG]rma_analytic to v12

This commit is contained in:
ahenriquez
2019-10-28 12:50:33 +01:00
committed by mreficent
parent 17641cccf7
commit 1ad29d168a
14 changed files with 284 additions and 79 deletions

View File

@@ -1,5 +1,5 @@
.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg
:target: https://www.gnu.org/licenses/lgpl.html
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: https://www.gnu.org/licenses/lgpl
:alt: License: LGPL-3
==========================

View File

@@ -1,5 +1,2 @@
# -*- coding: utf-8 -*-
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import models
from . import wizards

View File

@@ -1,19 +1,18 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Analytic Account in RMA",
"version": "10.0.1.0.0",
"author": "Eficent,"
"Odoo Community Association (OCA)",
"version": "12.0.1.0.0",
"author": "Eficent," "Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "http://www.eficent.com",
"category": "Analytic",
"depends": ["rma", "analytic", "procurement_analytic",
'stock_analytic_account'],
"data": [
"views/rma_order_line_view.xml"
"depends": [
"rma_account",
"stock_analytic",
"procurement_mto_analytic",
],
'installable': False,
"data": ["views/rma_order_line_view.xml"],
"installable": True,
}

View File

@@ -1,5 +1,2 @@
# -*- coding: utf-8 -*-
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import stock_move
from . import rma_order_line
from . import procurement

View File

@@ -1,19 +0,0 @@
# -*- coding: utf-8 -*-
# © 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, exceptions, models
class ProcurementOrder(models.Model):
_inherit = "procurement.order"
@api.constrains('analytic_account_id')
def check_analytic(self):
for order in self:
if (order.analytic_account_id !=
order.rma_line_id.analytic_account_id):
raise exceptions.ValidationError(
_("The analytic account in the procurement it's not the "
"same as in the rma line"))

View File

@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# © 2018 Eficent Business and IT Consulting Services S.L.
# 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 fields, models
from odoo import api, fields, models
class RmaOrderLine(models.Model):
@@ -10,6 +9,17 @@ class RmaOrderLine(models.Model):
_inherit = "rma.order.line"
analytic_account_id = fields.Many2one(
comodel_name='account.analytic.account',
string='Analytic Account',
comodel_name="account.analytic.account",
string="Analytic Account",
)
@api.multi
def _prepare_rma_line_from_inv_line(self, line):
res = super(
RmaOrderLine, self
)._prepare_rma_line_from_inv_line(line)
if line.account_analytic_id:
res.update(
analytic_account_id=line.account_analytic_id.id
)
return res

View File

@@ -0,0 +1,17 @@
# 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 models
class StockMove(models.Model):
_inherit = "stock.move"
def _prepare_procurement_values(self):
res = super(StockMove, self)._prepare_procurement_values()
res.update(
{
"account_analytic_id": self.rma_line_id.analytic_account_id.id
}
)
return res

View File

@@ -1,4 +1 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import test_rma_analytic

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo.addons.rma.tests import test_rma
@@ -7,26 +6,199 @@ from odoo.addons.rma.tests import test_rma
class TestRmaAnalytic(test_rma.TestRma):
def setUp(self):
super(TestRmaAnalytic, self).setUp()
products2move = [(self.product_1, 3), (self.product_2, 5),
(self.product_3, 2)]
self.rma_ana_id = self._create_rma_from_move(
products2move, 'supplier', self.env.ref('base.res_partner_1'),
dropship=False)
@classmethod
def setUpClass(cls):
super(TestRmaAnalytic, cls).setUpClass()
cls.rma_add_invoice_wiz = cls.env["rma_add_invoice"]
cls.rma_refund_wiz = cls.env["rma.refund"]
products2move = [
(cls.product_1, 3),
(cls.product_2, 5),
(cls.product_3, 2),
]
cls.rma_add_invoice_wiz = cls.env["rma_add_invoice"]
cls.rma_ana_id = cls._create_rma_from_move(
products2move,
"supplier",
cls.env.ref("base.res_partner_2"),
dropship=False,
)
receivable_type = cls.env.ref(
"account.data_account_type_receivable"
)
# Create Invoices:
customer_account = (
cls.env["account.account"]
.search(
[("user_type_id", "=", receivable_type.id)], limit=1
)
.id
)
cls.inv_customer = cls.env["account.invoice"].create(
{
"partner_id": cls.partner_id.id,
"account_id": customer_account,
"type": "out_invoice",
}
)
cls.anal = cls.env["account.analytic.account"].create(
{"name": "Name"}
)
cls.inv_line_1 = cls.env["account.invoice.line"].create(
{
"name": cls.partner_id.name,
"product_id": cls.product_1.id,
"quantity": 12.0,
"price_unit": 100.0,
"account_analytic_id": cls.anal.id,
"invoice_id": cls.inv_customer.id,
"uom_id": cls.product_1.uom_id.id,
"account_id": customer_account,
}
)
def _prepare_move(self, product, qty, src, dest, picking_in):
res = super(TestRmaAnalytic, self)._prepare_move(
product, qty, src, dest, picking_in)
analytic_1 = self.env['account.analytic.account'].create({
'name': 'Test account #1',
})
res.update({'analytic_account_id': analytic_1.id})
@classmethod
def _prepare_move(cls, product, qty, src, dest, picking_in):
res = super(TestRmaAnalytic, cls)._prepare_move(
product, qty, src, dest, picking_in
)
analytic_1 = cls.env["account.analytic.account"].create(
{"name": "Test account #1"}
)
res.update({"analytic_account_id": analytic_1.id})
return res
def test_analytic(self):
for line in self.rma_ana_id.rma_line_ids:
for move in line.move_ids:
self.assertEqual(
line.analytic_account_id, move.analytic_account_id,
"the analytic account is not propagated")
line.analytic_account_id,
move.analytic_account_id,
"the analytic account is not propagated",
)
def test_invoice_analytic(self):
"""Test wizard to create RMA from a customer invoice."""
rma_line = (
self.env["rma.order.line"]
.with_context(customer=True)
.new(
{
"partner_id": self.partner_id.id,
"product_id": self.product_1.id,
"operation_id": self.env.ref(
"rma.rma_operation_customer_replace"
).id,
"in_route_id": self.env.ref(
"rma.route_rma_customer"
),
"out_route_id": self.env.ref(
"rma.route_rma_customer"
),
"in_warehouse_id": self.env.ref(
"stock.warehouse0"
),
"out_warehouse_id": self.env.ref(
"stock.warehouse0"
),
"location_id": self.env.ref(
"stock.stock_location_stock"
),
"type": "customer",
"invoice_line_id": self.inv_line_1.id,
"uom_id": self.product_1.uom_id.id,
}
)
)
rma_line._onchange_invoice_line_id()
self.assertEqual(
rma_line.analytic_account_id,
self.inv_line_1.account_analytic_id,
)
def test_invoice_analytic02(self):
self.product_1.rma_customer_operation_id = self.env.ref(
"rma.rma_operation_customer_replace"
).id
rma_order = (
self.env["rma.order"]
.with_context(customer=True)
.create(
{
"name": "RMA",
"partner_id": self.partner_id.id,
"type": "customer",
"rma_line_ids": [],
}
)
)
add_inv = self.rma_add_invoice_wiz.with_context(
{
"customer": True,
"active_ids": [rma_order.id],
"active_model": "rma.order",
}
).create(
{
"invoice_line_ids": [
(6, 0, self.inv_customer.invoice_line_ids.ids)
]
}
)
add_inv.add_lines()
self.assertEqual(
rma_order.mapped("rma_line_ids.analytic_account_id"),
self.inv_line_1.account_analytic_id,
)
def test_refund_analytic(self):
self.product_1.rma_customer_operation_id = self.env.ref(
"rma_account.rma_operation_customer_refund"
).id
rma_line = (
self.env["rma.order.line"]
.with_context(customer=True)
.create(
{
"partner_id": self.partner_id.id,
"product_id": self.product_1.id,
"operation_id": self.env.ref(
"rma_account.rma_operation_customer_refund"
).id,
"in_route_id": self.env.ref(
"rma.route_rma_customer"
).id,
"out_route_id": self.env.ref(
"rma.route_rma_customer"
).id,
"in_warehouse_id": self.env.ref(
"stock.warehouse0"
).id,
"out_warehouse_id": self.env.ref(
"stock.warehouse0"
).id,
"location_id": self.env.ref(
"stock.stock_location_stock"
).id,
"type": "customer",
"invoice_line_id": self.inv_line_1.id,
"uom_id": self.product_1.uom_id.id,
}
)
)
rma_line._onchange_invoice_line_id()
rma_line.action_rma_to_approve()
rma_line.action_rma_approve()
make_refund = self.rma_refund_wiz.with_context(
{
"customer": True,
"active_ids": rma_line.ids,
"active_model": "rma.order.line",
}
).create({"description": "Test refund"})
make_refund.invoice_refund()
self.assertEqual(
rma_line.mapped("analytic_account_id"),
rma_line.mapped("refund_line_ids.account_analytic_id"),
)

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# © 2018 Eficent Business and IT Consulting Services S.L.
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from . import rma_add_stock_move
from . import rma_make_picking
from . import rma_add_invoice
from . import rma_refund

View File

@@ -0,0 +1,18 @@
# © 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 models
class RmaAddInvoice(models.TransientModel):
_inherit = "rma_add_invoice"
def _prepare_rma_line_from_inv_line(self, line):
res = super(
RmaAddInvoice, self
)._prepare_rma_line_from_inv_line(line)
if line.account_analytic_id:
res.update(
analytic_account_id=line.account_analytic_id.id
)
return res

View File

@@ -1,17 +1,16 @@
# -*- coding: utf-8 -*-
# © 2018 Eficent Business and IT Consulting Services S.L.
# 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, models
class RmaAddStockMove(models.TransientModel):
_inherit = 'rma_add_stock_move'
_description = 'Wizard to add rma lines from pickings'
_inherit = "rma_add_stock_move"
@api.model
def _prepare_rma_line_from_stock_move(self, sm, lot=False):
data = super(RmaAddStockMove, self)._prepare_rma_line_from_stock_move(
sm, lot)
data = super(
RmaAddStockMove, self
)._prepare_rma_line_from_stock_move(sm, lot)
data.update(analytic_account_id=sm.analytic_account_id.id)
return data

View File

@@ -1,18 +1,18 @@
# -*- coding: utf-8 -*-
# © 2018 Eficent Business and IT Consulting Services S.L.
# 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 models, api
class RmaMakePicking(models.TransientModel):
_name = 'rma_make_picking.wizard'
_description = 'Wizard to create pickings from rma lines'
_inherit = "rma_make_picking.wizard"
@api.model
def _get_procurement_data(self, item, group, qty, picking_type):
procurement_data = super(RmaMakePicking, self)._get_procurement_data(
item, group, qty, picking_type)
procurement_data = super(
RmaMakePicking, self
)._get_procurement_data(item, group, qty, picking_type)
procurement_data.update(
analytic_account_id=item.line_id.analytic_account_id.id)
analytic_account_id=item.line_id.analytic_account_id.id
)
return procurement_data

View File

@@ -0,0 +1,17 @@
# © 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, models
class RmaRefund(models.TransientModel):
_inherit = "rma.refund"
@api.model
def prepare_refund_line(self, item, refund):
res = super(RmaRefund, self).prepare_refund_line(item, refund)
if item.line_id.analytic_account_id:
res.update(
account_analytic_id=item.line_id.analytic_account_id.id
)
return res