diff --git a/rma_purchase/README.rst b/rma_purchase/README.rst index 2cd007c2..a2335f81 100644 --- a/rma_purchase/README.rst +++ b/rma_purchase/README.rst @@ -39,6 +39,7 @@ Contributors * Aaron Henriquez * Lois Rilo * Bhavesh Odedra +* Serpent Consulting Services Pvt. Ltd. Maintainer ---------- diff --git a/rma_purchase/__manifest__.py b/rma_purchase/__manifest__.py index a5a27eb1..19b6d255 100644 --- a/rma_purchase/__manifest__.py +++ b/rma_purchase/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'RMA Purchase', - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'category': 'RMA', 'summary': 'RMA from PO', 'license': 'LGPL-3', diff --git a/rma_purchase/models/rma_order.py b/rma_purchase/models/rma_order.py index d9fdcbf4..5fb4943c 100644 --- a/rma_purchase/models/rma_order.py +++ b/rma_purchase/models/rma_order.py @@ -20,6 +20,7 @@ class RmaOrder(models.Model): rec.po_count = po_count @api.multi + @api.depends('rma_line_ids') def _compute_origin_po_count(self): for rma in self: purchases = rma.mapped( diff --git a/rma_purchase/models/rma_order_line.py b/rma_purchase/models/rma_order_line.py index 8cc75280..fd79595d 100644 --- a/rma_purchase/models/rma_order_line.py +++ b/rma_purchase/models/rma_order_line.py @@ -78,6 +78,22 @@ class RmaOrderLine(models.Model): readonly=True, compute='_compute_qty_purchase' ) + @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'] = {} + domain = [ + '|', + ('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 + return res + @api.onchange('operation_id') def _onchange_operation_id(self): res = super(RmaOrderLine, self)._onchange_operation_id() @@ -122,8 +138,9 @@ class RmaOrderLine(models.Model): 'uom_id': line.product_uom.id, 'operation_id': operation.id, 'product_qty': line.product_qty, - 'price_unit': line.currency_id.compute( - line.price_unit, line.currency_id, round=False), + '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, diff --git a/rma_purchase/tests/test_rma_purchase.py b/rma_purchase/tests/test_rma_purchase.py index a165c1ba..f7fdb5cf 100644 --- a/rma_purchase/tests/test_rma_purchase.py +++ b/rma_purchase/tests/test_rma_purchase.py @@ -1,65 +1,64 @@ # 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 openerp.tests import common -from openerp.fields import Datetime +from odoo.tests import common +from odoo.fields import Datetime -class TestRmaPurchase(common.SingleTransactionCase): +class TestRmaPurchase(common.TransactionCase): - @classmethod - def setUpClass(cls): - super(TestRmaPurchase, cls).setUpClass() + def setUp(self): + super(TestRmaPurchase, self).setUp() - cls.rma_obj = cls.env['rma.order'] - cls.rma_line_obj = cls.env['rma.order.line'] - cls.rma_op_obj = cls.env['rma.operation'] - cls.rma_add_purchase_wiz = cls.env['rma_add_purchase'] - cls.po_obj = cls.env['purchase.order'] - cls.pol_obj = cls.env['purchase.order.line'] - cls.product_obj = cls.env['product.product'] - cls.partner_obj = cls.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'] - cls.rma_route_cust = cls.env.ref('rma.route_rma_customer') + self.rma_route_cust = self.env.ref('rma.route_rma_customer') # Create supplier - supplier1 = cls.partner_obj.create({'name': 'Supplier 1'}) + supplier1 = self.partner_obj.create({'name': 'Supplier 1'}) # Create products - cls.product_1 = cls.product_obj.create({ + self.product_1 = self.product_obj.create({ 'name': 'Test Product 1', 'type': 'product', }) - cls.product_2 = cls.product_obj.create({ + self.product_2 = self.product_obj.create({ 'name': 'Test Product 2', 'type': 'product', }) # Create PO: - cls.po = cls.po_obj.create({ + self.po = self.po_obj.create({ 'partner_id': supplier1.id, }) - cls.pol_1 = cls.pol_obj.create({ - 'name': cls.product_1.name, - 'order_id': cls.po.id, - 'product_id': cls.product_1.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': cls.product_1.uom_id.id, + 'product_uom': self.product_1.uom_id.id, 'price_unit': 100.0, 'date_planned': Datetime.now(), }) - cls.pol_2 = cls.pol_obj.create({ - 'name': cls.product_2.name, - 'order_id': cls.po.id, - 'product_id': cls.product_2.id, + 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': cls.product_2.uom_id.id, + 'product_uom': self.product_2.uom_id.id, 'price_unit': 150.0, 'date_planned': Datetime.now(), }) # Create RMA group: - cls.rma_group = cls.rma_obj.create({ + self.rma_group = self.rma_obj.create({ 'partner_id': supplier1.id, 'type': 'supplier', }) diff --git a/rma_purchase/views/rma_order_view.xml b/rma_purchase/views/rma_order_view.xml index f109af39..f5f61ed2 100644 --- a/rma_purchase/views/rma_order_view.xml +++ b/rma_purchase/views/rma_order_view.xml @@ -11,18 +11,16 @@ class="oe_stat_button" icon="fa-shopping-cart" groups="purchase.group_purchase_user"> - + - -
diff --git a/rma_purchase/wizards/rma_add_purchase.py b/rma_purchase/wizards/rma_add_purchase.py index 15e95e51..f84a81ef 100644 --- a/rma_purchase/wizards/rma_add_purchase.py +++ b/rma_purchase/wizards/rma_add_purchase.py @@ -70,8 +70,9 @@ class RmaAddPurchase(models.TransientModel): 'uom_id': line.product_uom.id, 'operation_id': operation.id, 'product_qty': line.product_qty, - 'price_unit': line.currency_id.compute( - line.price_unit, line.currency_id, round=False), + '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, diff --git a/rma_purchase/wizards/rma_add_purchase.xml b/rma_purchase/wizards/rma_add_purchase.xml index 1c467bef..e3337989 100644 --- a/rma_purchase/wizards/rma_add_purchase.xml +++ b/rma_purchase/wizards/rma_add_purchase.xml @@ -29,7 +29,7 @@ - + diff --git a/rma_purchase/wizards/rma_order_line_make_purchase_order.py b/rma_purchase/wizards/rma_order_line_make_purchase_order.py index 4d1c227d..cd34a4f1 100644 --- a/rma_purchase/wizards/rma_order_line_make_purchase_order.py +++ b/rma_purchase/wizards/rma_order_line_make_purchase_order.py @@ -139,5 +139,5 @@ class RmaLineMakePurchaseOrderItem(models.TransientModel): string='Quantity to purchase', digits=dp.get_precision('Product Unit of Measure'),) product_uom_id = fields.Many2one( - comodel_name='product.uom', string='UoM') + comodel_name='uom.uom', string='UoM') free_of_charge = fields.Boolean(string='Free of Charge') diff --git a/rma_purchase/wizards/rma_order_line_make_purchase_order_view.xml b/rma_purchase/wizards/rma_order_line_make_purchase_order_view.xml index 48455623..af9af097 100644 --- a/rma_purchase/wizards/rma_order_line_make_purchase_order_view.xml +++ b/rma_purchase/wizards/rma_order_line_make_purchase_order_view.xml @@ -30,7 +30,7 @@ + groups="uom.group_uom"/>