|
| 1 | +# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 | + |
| 3 | +from dateutil.relativedelta import relativedelta |
| 4 | + |
| 5 | +from odoo import fields |
| 6 | +from odoo.tests.common import TransactionCase |
| 7 | +from odoo.tests import Form, tagged |
| 8 | + |
| 9 | + |
| 10 | +@tagged('post_install', '-at_install') |
| 11 | +class ServerActionsTestCase(TransactionCase): |
| 12 | + |
| 13 | + @classmethod |
| 14 | + def setUpClass(cls): |
| 15 | + super().setUpClass() |
| 16 | + cls.tax_1 = cls.env['account.tax'].create([{ |
| 17 | + 'name': "tax_1", |
| 18 | + 'amount_type': 'percent', |
| 19 | + 'amount': 10.0, |
| 20 | + }]) |
| 21 | + cls.tax_2 = cls.env['account.tax'].create([{ |
| 22 | + 'name': "tax_2", |
| 23 | + 'amount_type': 'percent', |
| 24 | + 'amount': 5.0, |
| 25 | + 'type_tax_use': 'purchase', |
| 26 | + }]) |
| 27 | + cls.tax_3 = cls.env['account.tax'].create([{ |
| 28 | + 'name': "tax_3", |
| 29 | + 'amount_type': 'percent', |
| 30 | + 'amount': 20.0, |
| 31 | + }]) |
| 32 | + cls.tax_4 = cls.env['account.tax'].create([{ |
| 33 | + 'name': "tax_4", |
| 34 | + 'amount_type': 'percent', |
| 35 | + 'amount': 15.0, |
| 36 | + 'type_tax_use': 'purchase', |
| 37 | + }]) |
| 38 | + cls.product_template_deposit = cls.env['product.template'].create({ |
| 39 | + 'name': 'product template deposit', |
| 40 | + 'categ_id': cls.env['product.category'].create({ |
| 41 | + 'name': 'Deposit Category', |
| 42 | + 'x_is_a_deposit_category': True, |
| 43 | + }).id, |
| 44 | + 'invoice_policy': 'order', |
| 45 | + 'type': 'consu', |
| 46 | + 'is_storable': False, |
| 47 | + 'purchase_ok': True, |
| 48 | + 'taxes_id': cls.tax_1, |
| 49 | + 'supplier_taxes_id': cls.tax_2, |
| 50 | + }) |
| 51 | + cls.product_template = cls.env['product.template'].create({ |
| 52 | + 'name': 'product template', |
| 53 | + 'x_is_a_deposit': False, |
| 54 | + 'x_deposit_product_1': cls.product_template_deposit.id, |
| 55 | + 'x_quantity_by_deposit_product': 6, |
| 56 | + 'purchase_ok': True, |
| 57 | + 'taxes_id': cls.tax_3, |
| 58 | + 'supplier_taxes_id': cls.tax_4, |
| 59 | + 'x_unit_sale_product': cls.env['product.template'].create({ |
| 60 | + 'name': 'sale product', |
| 61 | + }).id, |
| 62 | + }) |
| 63 | + cls.product_uom = cls.env['uom.uom'].create({ |
| 64 | + 'name': 'Unit of Measure 1', |
| 65 | + 'rounding': 0.01 |
| 66 | + }) |
| 67 | + cls.manfacturing_order = cls.env['mrp.production'].create({ |
| 68 | + 'name': 'Manufacturing Order 1', |
| 69 | + 'date_finished': fields.Datetime.now() - relativedelta(days=2), |
| 70 | + 'product_qty': 2, |
| 71 | + 'priority': '1', |
| 72 | + 'is_locked': False, |
| 73 | + 'state': 'confirmed', |
| 74 | + 'product_id': cls.env['product.product'].create({ |
| 75 | + 'name': 'Product 1', |
| 76 | + 'standard_price': 600.0, |
| 77 | + 'list_price': 699.0, |
| 78 | + 'type': 'service', |
| 79 | + 'uom_id': cls.product_uom.id, |
| 80 | + }).id, |
| 81 | + 'product_uom_id': cls.product_uom.id, |
| 82 | + }) |
| 83 | + |
| 84 | + def test_make_deposit_storable_delivery_invoice_automation(self): |
| 85 | + product_form = Form(self.product_template_deposit) |
| 86 | + new_category = self.env['product.category'].create({ |
| 87 | + 'name': 'Deposit Category 2', |
| 88 | + 'x_is_a_deposit_category': True, |
| 89 | + }) |
| 90 | + product_form['categ_id'] = new_category |
| 91 | + product_form.save() |
| 92 | + |
| 93 | + self.assertEqual(self.product_template_deposit.invoice_policy, 'delivery', "Changing the product template to a deposit should set its invoice policy to delivery") |
| 94 | + self.assertEqual(self.product_template_deposit.type, 'consu', "Changing the product template to a deposit should set its type to consu") |
| 95 | + self.assertEqual(self.product_template_deposit.is_storable, True, "Changing the product template to a deposit should make it storable") |
| 96 | + |
| 97 | + def test_update_sales_taxes_automation(self): |
| 98 | + self.assertEqual(self.product_template.taxes_id, self.tax_1 + self.tax_3) |
| 99 | + self.assertEqual(self.product_template.supplier_taxes_id, self.tax_2 + self.tax_4) |
| 100 | + |
| 101 | + def test_update_state_automation(self): |
| 102 | + self.assertEqual(self.manfacturing_order.date_finished.date(), fields.Datetime.today().date()) |
| 103 | + self.assertEqual(self.manfacturing_order.priority, '0') |
| 104 | + self.assertEqual(self.manfacturing_order.is_locked, True) |
| 105 | + self.assertEqual(self.manfacturing_order.state, 'done') |
| 106 | + |
| 107 | + def test_bom_automation(self): |
| 108 | + existing_bom = self.env['mrp.bom'].search([('product_tmpl_id', '=', self.product_template.x_unit_sale_product.id)], limit=1) |
| 109 | + self.assertEqual(existing_bom.product_qty, self.product_template.x_quantity_by_deposit_product) |
| 110 | + self.assertEqual(existing_bom.type, 'normal') |
| 111 | + self.assertEqual(existing_bom.x_parent_product.id, self.product_template.id) |
| 112 | + self.assertEqual(existing_bom.x_auto_production, True) |
0 commit comments