| 1 |
|
| 2 |
|
| 3 |
from odoo.addons.sale.tests.common import TestSaleCommon |
| 4 |
from odoo.tests import Form, tagged |
| 5 |
|
| 6 |
|
| 7 |
@tagged('post_install_l10n', 'post_install', '-at_install') |
| 8 |
class TestDDT(TestSaleCommon): |
| 9 |
|
| 10 |
@classmethod |
| 11 |
@TestSaleCommon.setup_country('it') |
| 12 |
def setUpClass(cls): |
| 13 |
super().setUpClass() |
| 14 |
cls.company_data['company'].write({ |
| 15 |
'vat':"IT12345670017", |
| 16 |
'l10n_it_codice_fiscale': '01234560157', |
| 17 |
'l10n_it_tax_system': 'RF01', |
| 18 |
'street': 'Via Giovanni Maria Platina 66', |
| 19 |
'zip': '26100', |
| 20 |
'city': 'Cremona', |
| 21 |
}) |
| 22 |
cls.env['res.partner.bank'].create({ |
| 23 |
'acc_number': 'IT60X0542811101000000123456', |
| 24 |
'partner_id': cls.company_data['company'].partner_id.id, |
| 25 |
}) |
| 26 |
cls.partner_a.write({ |
| 27 |
'street': 'Piazza Guglielmo Marconi 5', |
| 28 |
'zip': '26100', |
| 29 |
'city': 'Cremona', |
| 30 |
'country_id': cls.env.ref('base.it').id, |
| 31 |
'vat': 'IT12345670124' |
| 32 |
}) |
| 33 |
|
| 34 |
settings = cls.env['res.config.settings'].create({}) |
| 35 |
if hasattr(settings, '_create_proxy_user'): |
| 36 |
|
| 37 |
settings._create_proxy_user(cls.company_data['company'], 'demo') |
| 38 |
|
| 39 |
def test_ddt_flow(self): |
| 40 |
""" |
| 41 |
We confirm a sale order and handle its delivery partially. |
| 42 |
This should have created a DDT number and when we generate and the invoice, |
| 43 |
the delivery should be linked to it as DDT. |
| 44 |
""" |
| 45 |
self.so = self.env['sale.order'].create({ |
| 46 |
'partner_id': self.partner_a.id, |
| 47 |
'partner_invoice_id': self.partner_a.id, |
| 48 |
'partner_shipping_id': self.partner_a.id, |
| 49 |
'order_line': [(0, 0, {'name': p.name, |
| 50 |
'product_id': p.id, |
| 51 |
'product_uom_qty': 5, |
| 52 |
'price_unit': p.list_price, |
| 53 |
'tax_ids': self.company_data['default_tax_sale']}) |
| 54 |
for p in ( |
| 55 |
self.company_data['product_order_no'], |
| 56 |
self.company_data['product_service_delivery'], |
| 57 |
self.company_data['product_service_order'], |
| 58 |
self.company_data['product_delivery_no'], |
| 59 |
)], |
| 60 |
'picking_policy': 'direct', |
| 61 |
}) |
| 62 |
self.so.action_confirm() |
| 63 |
|
| 64 |
|
| 65 |
pick = self.so.picking_ids |
| 66 |
pick.move_ids.write({'quantity': 1, 'picked': True}) |
| 67 |
Form.from_action(self.env, pick.button_validate()).save().process() |
| 68 |
|
| 69 |
self.assertTrue(pick.l10n_it_ddt_number, 'The outgoing picking should have a DDT number') |
| 70 |
self.inv1 = self.so._create_invoices() |
| 71 |
self.inv1.action_post() |
| 72 |
self.assertEqual(self.inv1.l10n_it_ddt_ids.ids, pick.ids, 'DDT should be linked to the invoice') |
| 73 |
|
| 74 |
|
| 75 |
pickx1 = self.so.picking_ids.filtered(lambda p: p.state != 'done') |
| 76 |
pickx1.move_ids.write({'quantity': 1, 'picked': True}) |
| 77 |
Form.from_action(self.env, pickx1.button_validate()).save().process() |
| 78 |
|
| 79 |
|
| 80 |
pickx2 = self.so.picking_ids.filtered(lambda p: p.state != 'done') |
| 81 |
pickx2.move_ids.write({'quantity': 2, 'picked': True}) |
| 82 |
Form.from_action(self.env, pickx2.button_validate()).save().process() |
| 83 |
|
| 84 |
self.inv2 = self.so._create_invoices() |
| 85 |
self.inv2.action_post() |
| 86 |
self.inv2.flush_model() |
| 87 |
self.inv2.invalidate_model() |
| 88 |
self.assertIn(pickx1, self.inv2.l10n_it_ddt_ids) |
| 89 |
self.assertIn(pickx2, self.inv2.l10n_it_ddt_ids) |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
def test_ddt_flow_2(self): |
| 96 |
""" |
| 97 |
Test that the link between the invoice lines and the deliveries linked to the invoice |
| 98 |
through the link with the sale order is calculated correctly. |
| 99 |
""" |
| 100 |
so = self.env['sale.order'].create({ |
| 101 |
'partner_id': self.partner_a.id, |
| 102 |
'order_line': [(0, 0, { |
| 103 |
'product_id': self.product_a.id, |
| 104 |
'product_uom_qty': 3, |
| 105 |
'price_unit': self.product_a.list_price, |
| 106 |
'tax_ids': self.company_data['default_tax_sale'] |
| 107 |
} |
| 108 |
)], |
| 109 |
'picking_policy': 'direct', |
| 110 |
}) |
| 111 |
so.action_confirm() |
| 112 |
|
| 113 |
|
| 114 |
picking_1 = so.picking_ids |
| 115 |
picking_1.move_ids.write({'quantity': 1, 'picked': True}) |
| 116 |
Form.from_action(self.env, picking_1.button_validate()).save().process() |
| 117 |
|
| 118 |
invoice_1 = so._create_invoices() |
| 119 |
invoice_1.invoice_line_ids[0].quantity = 1.0 |
| 120 |
invoice_1.action_post() |
| 121 |
|
| 122 |
picking_2 = so.picking_ids.filtered(lambda p: p.state != 'done') |
| 123 |
picking_2.move_ids.write({'quantity': 2, 'picked': True}) |
| 124 |
picking_2.button_validate() |
| 125 |
|
| 126 |
invoice_2 = so._create_invoices() |
| 127 |
invoice_2.action_post() |
| 128 |
|
| 129 |
|
| 130 |
picking_2.invalidate_model() |
| 131 |
self.assertEqual(invoice_1.l10n_it_ddt_ids.ids, picking_1.ids, 'DDT picking_1 should be linked to the invoice_1') |
| 132 |
self.assertEqual(invoice_2.l10n_it_ddt_ids.ids, picking_2.ids, 'DDT picking_2 should be linked to the invoice_2') |