This commit is contained in:
Damien Crier
2020-08-10 14:07:28 +02:00
committed by Florian da Costa
parent 01bb6375ef
commit 8de48a5b12
4 changed files with 179 additions and 139 deletions

View File

@@ -7,7 +7,7 @@ import os
import sys
import traceback
from odoo import _, api, fields, models
from odoo import _, fields, models
from odoo.exceptions import UserError, ValidationError
from ..parser.parser import new_move_parser
@@ -234,14 +234,16 @@ class AccountJournal(models.Model):
"currency_id": self.currency_id.id,
"company_currency_id": self.company_id.currency_id.id,
"journal_id": self.id,
"account_id": account.id,
"move_id": move.id,
"date": move.date,
"balance": values["debit"] - values["credit"],
"amount_residual_currency": 0,
"user_type_id": account.user_type_id.id,
"reconciled": False,
}
)
if self.currency_id and self.currency_id == self.company_id.currency_id:
del values["currency_id"]
values = move_line_obj._add_missing_default_values(values)
return values
@@ -251,7 +253,7 @@ class AccountJournal(models.Model):
"""
vals = {
"journal_id": self.id,
"currency_id": self.currency_id.id,
"currency_id": self.currency_id.id or self.company_id.currency_id.id,
"import_partner_id": self.partner_id.id,
}
vals.update(parser.get_move_vals())
@@ -322,14 +324,14 @@ class AccountJournal(models.Model):
if self.create_counterpart:
self._create_counterpart(parser, move)
# Check if move is balanced
move.assert_balanced()
move._check_balanced()
# Computed total amount of the move
move._amount_compute()
# move._amount_compute()
# Attach data to the move
attachment_data = {
"name": "statement file",
"datas": file_stream,
"datas_fname": "{}.{}".format(fields.Date.today(), ftype),
"store_fname": "{}.{}".format(fields.Date.today(), ftype),
"res_model": "account.move",
"res_id": move.id,
}

View File

@@ -76,10 +76,10 @@ class AccountMoveCompletionRule(models.Model):
inv_obj = self.env["account.move"]
if inv_type == "supplier":
type_domain = ("in_invoice", "in_refund")
number_field = "reference"
number_field = "ref"
elif inv_type == "customer":
type_domain = ("out_invoice", "out_refund")
number_field = "number"
number_field = "name"
else:
raise ValidationError(
_("Invalid invoice type for completion: %s") % inv_type
@@ -111,7 +111,7 @@ class AccountMoveCompletionRule(models.Model):
invoice = self._find_invoice(line, inv_type)
if invoice:
partner_id = invoice.commercial_partner_id.id
res = {"partner_id": partner_id, "account_id": invoice.account_id.id}
res = {"partner_id": partner_id}
return res
# Should be private but data are initialised with no update XML

View File

@@ -93,7 +93,7 @@ class BaseCompletion(common.TransactionCase):
self.assertFalse(
self.move_line.partner_id, "Partner_id must be blank before completion"
)
self.move.button_auto_completion()
self.move.with_context(check_move_validity=False).button_auto_completion()
if case.should_match:
self.assertEqual(
self.partner,

View File

@@ -34,7 +34,10 @@ class TestInvoice(SingleTransactionCase):
self.account_id = self.env.ref("account.a_recv")
# I create a customer Invoice to be found by the completion.
product_3 = self.env.ref("product.product_product_3")
self.invoice_for_completion_1 = self.env["account.move"].with_context(default_type='out_invoice').create(
self.invoice_for_completion_1 = (
self.env["account.move"]
.with_context(default_type="out_invoice")
.create(
{
"currency_id": self.env.ref("base.EUR").id,
"type": "out_invoice",
@@ -47,7 +50,9 @@ class TestInvoice(SingleTransactionCase):
"product_id": product_3.id,
"price_unit": 210.0,
"quantity": 1.0,
"uom_id": self.env.ref("uom.product_uom_unit").id,
"product_uom_id": self.env.ref(
"uom.product_uom_unit"
).id,
"account_id": self.env.ref("account.a_sale").id,
},
)
@@ -56,13 +61,14 @@ class TestInvoice(SingleTransactionCase):
"partner_id": self.partner.id,
}
)
)
# I confirm the Invoice
self.invoice_for_completion_1.post()
# I check that the invoice state is "Open"
self.assertEqual(self.invoice_for_completion_1.state, "open")
self.assertEqual(self.invoice_for_completion_1.state, "posted")
# I check that it is given the number "TBNK/%Y/0001"
self.assertEqual(
self.invoice_for_completion_1.number,
self.invoice_for_completion_1.name,
fields.Date.today().strftime("TBNK/%Y/0001"),
)
@@ -71,14 +77,17 @@ class TestInvoice(SingleTransactionCase):
product_delivery = self.env.ref("product.product_delivery_01")
product_order = self.env.ref("product.product_order_01")
exp_account = self.env.ref("account.a_expense")
rec_account = self.env.ref("account.a_recv")
demo_invoice_0 = self.env["account.move"].with_context(default_type='in_invoice').create(
demo_invoice_0 = (
self.env["account.move"]
.with_context(default_type="in_invoice")
.create(
{
"partner_id": self.partner.id,
"invoice_payment_term_id": self.env.ref(
"account.account_payment_term_advance"
).id,
"type": "in_invoice",
"payment_term_id": self.env.ref("account.account_payment_term").id,
"type": "in_invoice",
"date_invoice": fields.Date.today().replace(day=1),
"invoice_date": fields.Date.today().replace(day=1),
"invoice_line_ids": [
(
0,
@@ -87,8 +96,10 @@ class TestInvoice(SingleTransactionCase):
"price_unit": 10.0,
"quantity": 1.0,
"product_id": product_delivery.id,
"product_uom_id": self.env.ref(
"uom.product_uom_unit"
).id,
"name": product_delivery.name,
"uom_id": self.env.ref("uom.product_uom_unit").id,
"account_id": exp_account.id,
},
),
@@ -100,26 +111,27 @@ class TestInvoice(SingleTransactionCase):
"quantity": 1.0,
"product_id": product_order.id,
"name": product_order.name,
"uom_id": self.env.ref("uom.product_uom_unit").id,
"product_uom_id": self.env.ref(
"uom.product_uom_unit"
).id,
"account_id": exp_account.id,
},
),
],
}
)
)
# I check that my invoice is a supplier invoice
self.assertEqual(demo_invoice_0.type, "in_invoice", msg="Check invoice type")
# I add a reference to an existing supplier invoice
demo_invoice_0.write({"reference": "T2S12345"})
demo_invoice_0.write({"ref": "T2S12345"})
# I check a second time that my invoice is still a supplier invoice
self.assertEqual(demo_invoice_0.type, "in_invoice", msg="Check invoice type 2")
# Now I confirm it
demo_invoice_0.post()
# I check that the supplier number is there
self.assertEqual(
demo_invoice_0.reference, "T2S12345", msg="Check supplier number"
)
self.assertEqual(demo_invoice_0.ref, "T2S12345", msg="Check supplier number")
# I check a third time that my invoice is still a supplier invoice
self.assertEqual(demo_invoice_0.type, "in_invoice", msg="Check invoice type 3")
@@ -129,15 +141,16 @@ class TestInvoice(SingleTransactionCase):
res_partner_12_child = self.env["res.partner"].create(
{
"name": "Child Partner",
"supplier": False,
"customer": True,
"is_company": False,
"parent_id": self.partner.id,
}
)
# I create a customer refund to be found by the completion.
product_3 = self.env.ref("product.product_product_3")
self.refund_for_completion_1 = self.env["account.move"].with_context(default_type="out_refund").create(
self.refund_for_completion_1 = (
self.env["account.move"]
.with_context(default_type="out_refund")
.create(
{
"currency_id": self.env.ref("base.EUR").id,
"invoice_line_ids": [
@@ -149,7 +162,9 @@ class TestInvoice(SingleTransactionCase):
"product_id": product_3.id,
"price_unit": 210.0,
"quantity": 1.0,
"uom_id": self.env.ref("uom.product_uom_unit").id,
"product_uom_id": self.env.ref(
"uom.product_uom_unit"
).id,
"account_id": self.env.ref("account.a_sale").id,
},
)
@@ -159,14 +174,15 @@ class TestInvoice(SingleTransactionCase):
"type": "out_refund",
}
)
)
# I confirm the refund
self.refund_for_completion_1.post()
# I check that the refund state is "Open"
self.assertEqual(self.refund_for_completion_1.state, "open")
self.assertEqual(self.refund_for_completion_1.state, "posted")
# I check that it is given the number "RTEXJ/%Y/0001"
self.assertEqual(
self.refund_for_completion_1.number,
self.refund_for_completion_1.name,
fields.Date.today().strftime("RTEXJ/%Y/0001"),
)
@@ -202,11 +218,16 @@ class TestInvoice(SingleTransactionCase):
)
# Now I create a statement. I create statment lines separately because
# I need to find each one by XML id
move_test1 = self.env["account.move"].create(
{"name": "Move 2", "journal_id": self.journal.id}
move_test1 = (
self.env["account.move"]
.with_context(check_move_validity=False)
.create({"name": "Move 2", "journal_id": self.journal.id})
)
# I create a move line for a CI
move_line_ci = self.env["account.move.line"].create(
move_line_ci = (
self.env["account.move.line"]
.with_context(check_move_validity=False)
.create(
{
"name": "\\",
"account_id": self.env.ref("account.a_sale").id,
@@ -215,8 +236,12 @@ class TestInvoice(SingleTransactionCase):
"credit": 0.0,
}
)
)
# I create a move line for a SI
move_line_si = self.env["account.move.line"].create(
move_line_si = (
self.env["account.move.line"]
.with_context(check_move_validity=False)
.create(
{
"name": "\\",
"account_id": self.env.ref("account.a_expense").id,
@@ -225,8 +250,12 @@ class TestInvoice(SingleTransactionCase):
"debit": 0.0,
}
)
)
# I create a move line for a CR
move_line_cr = self.env["account.move.line"].create(
move_line_cr = (
self.env["account.move.line"]
.with_context(check_move_validity=False)
.create(
{
"name": "\\",
"account_id": self.env.ref("account.a_expense").id,
@@ -235,8 +264,12 @@ class TestInvoice(SingleTransactionCase):
"debit": 0.0,
}
)
)
# I create a move line for the Partner Name
move_line_partner_name = self.env["account.move.line"].create(
move_line_partner_name = (
self.env["account.move.line"]
.with_context(check_move_validity=False)
.create(
{
"name": "Test autocompletion based on Partner Name Azure Interior",
"account_id": self.env.ref("account.a_sale").id,
@@ -245,8 +278,12 @@ class TestInvoice(SingleTransactionCase):
"credit": 0.0,
}
)
)
# I create a move line for the Partner Label
move_line_partner_label = self.env["account.move.line"].create(
move_line_partner_label = (
self.env["account.move.line"]
.with_context(check_move_validity=False)
.create(
{
"name": "XXX66Z",
"account_id": self.env.ref("account.a_sale").id,
@@ -255,6 +292,7 @@ class TestInvoice(SingleTransactionCase):
"debit": 0.0,
}
)
)
# and add the correct name
move_line_ci.with_context(check_move_validity=False).write(
{"name": fields.Date.today().strftime("TBNK/%Y/0001"), "credit": 210.0}