|
3 | 3 | # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
4 | 4 | from psycopg2 import IntegrityError |
5 | 5 |
|
| 6 | +from odoo import Command |
6 | 7 | from odoo.exceptions import UserError, ValidationError |
7 | 8 | from odoo.tests import Form |
8 | 9 | from odoo.tests.common import TransactionCase |
@@ -158,6 +159,80 @@ def test_invoice_report_with_intrastat_lines(self): |
158 | 159 | self.invoice.compute_intrastat_lines() |
159 | 160 | self._test_invoice_report(2) |
160 | 161 |
|
| 162 | + def test_zero_price_lines_transaction_23(self): |
| 163 | + """Zero price lines included in Intrastat must use transaction 23 |
| 164 | + and the product's sale price as fiscal value.""" |
| 165 | + self.demo_company.intrastat_include_zero_price_lines = True |
| 166 | + product_c3po = self.product_c3po.product_variant_ids[0] |
| 167 | + list_price = product_c3po.list_price |
| 168 | + self.assertTrue(list_price, "Product must have a list_price for this test") |
| 169 | + invoice = self.env["account.move"].create( |
| 170 | + { |
| 171 | + "move_type": "out_invoice", |
| 172 | + "partner_id": self.partner.id, |
| 173 | + "fiscal_position_id": self.position.id, |
| 174 | + "invoice_line_ids": [ |
| 175 | + Command.create( |
| 176 | + { |
| 177 | + "product_id": product_c3po.id, |
| 178 | + "quantity": 3, |
| 179 | + "price_unit": 0.0, |
| 180 | + "name": "Warranty replacement", |
| 181 | + }, |
| 182 | + ) |
| 183 | + ], |
| 184 | + } |
| 185 | + ) |
| 186 | + invoice.action_post() |
| 187 | + declaration = self.declaration_obj.create( |
| 188 | + { |
| 189 | + "company_id": self.demo_company.id, |
| 190 | + "declaration_type": "dispatches", |
| 191 | + } |
| 192 | + ) |
| 193 | + declaration.action_gather() |
| 194 | + zero_lines = declaration.computation_line_ids.filtered( |
| 195 | + lambda l: l.invoice_line_id.move_id == invoice |
| 196 | + ) |
| 197 | + self.assertEqual(len(zero_lines), 1) |
| 198 | + tr_23 = self.env.ref("intrastat_product.intrastat_transaction_23") |
| 199 | + self.assertEqual(zero_lines.transaction_id, tr_23) |
| 200 | + self.assertEqual(zero_lines.amount_company_currency, list_price * 3) |
| 201 | + |
| 202 | + def test_zero_price_lines_excluded_by_default(self): |
| 203 | + """Zero price lines must be excluded when config is disabled.""" |
| 204 | + self.demo_company.intrastat_include_zero_price_lines = False |
| 205 | + product_c3po = self.product_c3po.product_variant_ids[0] |
| 206 | + invoice = self.env["account.move"].create( |
| 207 | + { |
| 208 | + "move_type": "out_invoice", |
| 209 | + "partner_id": self.partner.id, |
| 210 | + "fiscal_position_id": self.position.id, |
| 211 | + "invoice_line_ids": [ |
| 212 | + Command.create( |
| 213 | + { |
| 214 | + "product_id": product_c3po.id, |
| 215 | + "quantity": 1, |
| 216 | + "price_unit": 0.0, |
| 217 | + "name": "Warranty replacement", |
| 218 | + }, |
| 219 | + ) |
| 220 | + ], |
| 221 | + } |
| 222 | + ) |
| 223 | + invoice.action_post() |
| 224 | + declaration = self.declaration_obj.create( |
| 225 | + { |
| 226 | + "company_id": self.demo_company.id, |
| 227 | + "declaration_type": "dispatches", |
| 228 | + } |
| 229 | + ) |
| 230 | + declaration.action_gather() |
| 231 | + zero_lines = declaration.computation_line_ids.filtered( |
| 232 | + lambda l: l.invoice_line_id.move_id == invoice |
| 233 | + ) |
| 234 | + self.assertFalse(zero_lines) |
| 235 | + |
161 | 236 |
|
162 | 237 | class TestIntrastatProductCase(TestIntrastatProduct, TransactionCase): |
163 | 238 | """Test Intrastat Product""" |
0 commit comments