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

View File

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

View File

@@ -93,7 +93,7 @@ class BaseCompletion(common.TransactionCase):
self.assertFalse( self.assertFalse(
self.move_line.partner_id, "Partner_id must be blank before completion" 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: if case.should_match:
self.assertEqual( self.assertEqual(
self.partner, self.partner,

View File

@@ -34,35 +34,41 @@ class TestInvoice(SingleTransactionCase):
self.account_id = self.env.ref("account.a_recv") self.account_id = self.env.ref("account.a_recv")
# I create a customer Invoice to be found by the completion. # I create a customer Invoice to be found by the completion.
product_3 = self.env.ref("product.product_product_3") 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"]
"currency_id": self.env.ref("base.EUR").id, .with_context(default_type="out_invoice")
"type": "out_invoice", .create(
"invoice_line_ids": [ {
( "currency_id": self.env.ref("base.EUR").id,
0, "type": "out_invoice",
0, "invoice_line_ids": [
{ (
"name": "[PCSC234] PC Assemble SC234", 0,
"product_id": product_3.id, 0,
"price_unit": 210.0, {
"quantity": 1.0, "name": "[PCSC234] PC Assemble SC234",
"uom_id": self.env.ref("uom.product_uom_unit").id, "product_id": product_3.id,
"account_id": self.env.ref("account.a_sale").id, "price_unit": 210.0,
}, "quantity": 1.0,
) "product_uom_id": self.env.ref(
], "uom.product_uom_unit"
"journal_id": self.journal.id, ).id,
"partner_id": self.partner.id, "account_id": self.env.ref("account.a_sale").id,
} },
)
],
"journal_id": self.journal.id,
"partner_id": self.partner.id,
}
)
) )
# I confirm the Invoice # I confirm the Invoice
self.invoice_for_completion_1.post() self.invoice_for_completion_1.post()
# I check that the invoice state is "Open" # 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" # I check that it is given the number "TBNK/%Y/0001"
self.assertEqual( self.assertEqual(
self.invoice_for_completion_1.number, self.invoice_for_completion_1.name,
fields.Date.today().strftime("TBNK/%Y/0001"), fields.Date.today().strftime("TBNK/%Y/0001"),
) )
@@ -71,55 +77,61 @@ class TestInvoice(SingleTransactionCase):
product_delivery = self.env.ref("product.product_delivery_01") product_delivery = self.env.ref("product.product_delivery_01")
product_order = self.env.ref("product.product_order_01") product_order = self.env.ref("product.product_order_01")
exp_account = self.env.ref("account.a_expense") exp_account = self.env.ref("account.a_expense")
rec_account = self.env.ref("account.a_recv") demo_invoice_0 = (
demo_invoice_0 = self.env["account.move"].with_context(default_type='in_invoice').create( self.env["account.move"]
{ .with_context(default_type="in_invoice")
"partner_id": self.partner.id, .create(
"type": "in_invoice", {
"payment_term_id": self.env.ref("account.account_payment_term").id, "partner_id": self.partner.id,
"type": "in_invoice", "invoice_payment_term_id": self.env.ref(
"date_invoice": fields.Date.today().replace(day=1), "account.account_payment_term_advance"
"invoice_line_ids": [ ).id,
( "type": "in_invoice",
0, "invoice_date": fields.Date.today().replace(day=1),
0, "invoice_line_ids": [
{ (
"price_unit": 10.0, 0,
"quantity": 1.0, 0,
"product_id": product_delivery.id, {
"name": product_delivery.name, "price_unit": 10.0,
"uom_id": self.env.ref("uom.product_uom_unit").id, "quantity": 1.0,
"account_id": exp_account.id, "product_id": product_delivery.id,
}, "product_uom_id": self.env.ref(
), "uom.product_uom_unit"
( ).id,
0, "name": product_delivery.name,
0, "account_id": exp_account.id,
{ },
"price_unit": 4.0, ),
"quantity": 1.0, (
"product_id": product_order.id, 0,
"name": product_order.name, 0,
"uom_id": self.env.ref("uom.product_uom_unit").id, {
"account_id": exp_account.id, "price_unit": 4.0,
}, "quantity": 1.0,
), "product_id": product_order.id,
], "name": product_order.name,
} "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 # I check that my invoice is a supplier invoice
self.assertEqual(demo_invoice_0.type, "in_invoice", msg="Check invoice type") self.assertEqual(demo_invoice_0.type, "in_invoice", msg="Check invoice type")
# I add a reference to an existing supplier invoice # 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 # 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") self.assertEqual(demo_invoice_0.type, "in_invoice", msg="Check invoice type 2")
# Now I confirm it # Now I confirm it
demo_invoice_0.post() demo_invoice_0.post()
# I check that the supplier number is there # I check that the supplier number is there
self.assertEqual( self.assertEqual(demo_invoice_0.ref, "T2S12345", msg="Check supplier number")
demo_invoice_0.reference, "T2S12345", msg="Check supplier number"
)
# I check a third time that my invoice is still a supplier invoice # 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") self.assertEqual(demo_invoice_0.type, "in_invoice", msg="Check invoice type 3")
@@ -129,44 +141,48 @@ class TestInvoice(SingleTransactionCase):
res_partner_12_child = self.env["res.partner"].create( res_partner_12_child = self.env["res.partner"].create(
{ {
"name": "Child Partner", "name": "Child Partner",
"supplier": False,
"customer": True,
"is_company": False, "is_company": False,
"parent_id": self.partner.id, "parent_id": self.partner.id,
} }
) )
# I create a customer refund to be found by the completion. # I create a customer refund to be found by the completion.
product_3 = self.env.ref("product.product_product_3") 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"]
"currency_id": self.env.ref("base.EUR").id, .with_context(default_type="out_refund")
"invoice_line_ids": [ .create(
( {
0, "currency_id": self.env.ref("base.EUR").id,
0, "invoice_line_ids": [
{ (
"name": "[PCSC234] PC Assemble SC234", 0,
"product_id": product_3.id, 0,
"price_unit": 210.0, {
"quantity": 1.0, "name": "[PCSC234] PC Assemble SC234",
"uom_id": self.env.ref("uom.product_uom_unit").id, "product_id": product_3.id,
"account_id": self.env.ref("account.a_sale").id, "price_unit": 210.0,
}, "quantity": 1.0,
) "product_uom_id": self.env.ref(
], "uom.product_uom_unit"
"journal_id": self.env.ref("account.expenses_journal").id, ).id,
"partner_id": res_partner_12_child.id, "account_id": self.env.ref("account.a_sale").id,
"type": "out_refund", },
} )
],
"journal_id": self.env.ref("account.expenses_journal").id,
"partner_id": res_partner_12_child.id,
"type": "out_refund",
}
)
) )
# I confirm the refund # I confirm the refund
self.refund_for_completion_1.post() self.refund_for_completion_1.post()
# I check that the refund state is "Open" # 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" # I check that it is given the number "RTEXJ/%Y/0001"
self.assertEqual( self.assertEqual(
self.refund_for_completion_1.number, self.refund_for_completion_1.name,
fields.Date.today().strftime("RTEXJ/%Y/0001"), fields.Date.today().strftime("RTEXJ/%Y/0001"),
) )
@@ -202,58 +218,80 @@ class TestInvoice(SingleTransactionCase):
) )
# Now I create a statement. I create statment lines separately because # Now I create a statement. I create statment lines separately because
# I need to find each one by XML id # I need to find each one by XML id
move_test1 = self.env["account.move"].create( move_test1 = (
{"name": "Move 2", "journal_id": self.journal.id} 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 # 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"]
"name": "\\", .with_context(check_move_validity=False)
"account_id": self.env.ref("account.a_sale").id, .create(
"move_id": move_test1.id, {
"date_maturity": fields.Date.from_string("2013-12-20"), "name": "\\",
"credit": 0.0, "account_id": self.env.ref("account.a_sale").id,
} "move_id": move_test1.id,
"date_maturity": fields.Date.from_string("2013-12-20"),
"credit": 0.0,
}
)
) )
# I create a move line for a SI # 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"]
"name": "\\", .with_context(check_move_validity=False)
"account_id": self.env.ref("account.a_expense").id, .create(
"move_id": move_test1.id, {
"date_maturity": fields.Date.from_string("2013-12-19"), "name": "\\",
"debit": 0.0, "account_id": self.env.ref("account.a_expense").id,
} "move_id": move_test1.id,
"date_maturity": fields.Date.from_string("2013-12-19"),
"debit": 0.0,
}
)
) )
# I create a move line for a CR # 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"]
"name": "\\", .with_context(check_move_validity=False)
"account_id": self.env.ref("account.a_expense").id, .create(
"move_id": move_test1.id, {
"date_maturity": fields.Date.from_string("2013-12-19"), "name": "\\",
"debit": 0.0, "account_id": self.env.ref("account.a_expense").id,
} "move_id": move_test1.id,
"date_maturity": fields.Date.from_string("2013-12-19"),
"debit": 0.0,
}
)
) )
# I create a move line for the Partner Name # 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"]
"name": "Test autocompletion based on Partner Name Azure Interior", .with_context(check_move_validity=False)
"account_id": self.env.ref("account.a_sale").id, .create(
"move_id": move_test1.id, {
"date_maturity": fields.Date.from_string("2013-12-17"), "name": "Test autocompletion based on Partner Name Azure Interior",
"credit": 0.0, "account_id": self.env.ref("account.a_sale").id,
} "move_id": move_test1.id,
"date_maturity": fields.Date.from_string("2013-12-17"),
"credit": 0.0,
}
)
) )
# I create a move line for the Partner Label # 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"]
"name": "XXX66Z", .with_context(check_move_validity=False)
"account_id": self.env.ref("account.a_sale").id, .create(
"move_id": move_test1.id, {
"date_maturity": "2013-12-24", "name": "XXX66Z",
"debit": 0.0, "account_id": self.env.ref("account.a_sale").id,
} "move_id": move_test1.id,
"date_maturity": "2013-12-24",
"debit": 0.0,
}
)
) )
# and add the correct name # and add the correct name
move_line_ci.with_context(check_move_validity=False).write( move_line_ci.with_context(check_move_validity=False).write(