[IMP] account_move_so_import: black, isort, prettier

pull/623/head
Florian da Costa 2021-05-11 17:40:18 +02:00 committed by clementmbr
parent f9de78e6e5
commit 2250957fd7
7 changed files with 108 additions and 75 deletions

View File

@ -1,18 +1,18 @@
# Copyright 2011-2019 Camptocamp SA # Copyright 2011-2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
{ {
'name': "Journal Entry Sale Order completion", "name": "Journal Entry Sale Order completion",
'version': '12.0.1.0.0', "version": "12.0.1.0.0",
'author': "Camptocamp,Odoo Community Association (OCA)", "author": "Camptocamp,Odoo Community Association (OCA)",
'maintainer': 'Camptocamp', "maintainer": "Camptocamp",
'category': 'Finance', "category": "Finance",
'complexity': 'easy', "complexity": "easy",
'depends': ['account_move_base_import', 'sale'], "depends": ["account_move_base_import", "sale"],
'website': 'http://www.camptocamp.com', "website": "https://github.com/OCA/account-reconcile",
'data': [ "data": [
'data/completion_rule_data.xml', "data/completion_rule_data.xml",
], ],
'installable': True, "installable": True,
'auto_install': False, "auto_install": False,
'license': 'AGPL-3', "license": "AGPL-3",
} }

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1"> <odoo noupdate="1">
<record id="bank_statement_completion_rule_1" model="account.move.completion.rule"> <record id="bank_statement_completion_rule_1" model="account.move.completion.rule">

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2011-2016 Camptocamp SA # © 2011-2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from . import account_move from . import account_move

View File

@ -1,8 +1,8 @@
# Copyright 2011-2019 Camptocamp SA # Copyright 2011-2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import _, fields, models from odoo import _, fields, models
from odoo.addons.account_move_base_import.models.account_move \
import ErrorTooManyPartner from odoo.addons.account_move_base_import.models.account_move import ErrorTooManyPartner
class AccountMoveCompletionRule(models.Model): class AccountMoveCompletionRule(models.Model):
@ -11,9 +11,8 @@ class AccountMoveCompletionRule(models.Model):
_inherit = "account.move.completion.rule" _inherit = "account.move.completion.rule"
function_to_call = fields.Selection( function_to_call = fields.Selection(
selection_add=[ selection_add=[("get_from_name_and_so", "From line name (based on SO number)")]
('get_from_name_and_so', 'From line name (based on SO number)') )
])
# Should be private but data are initialized with no update XML # Should be private but data are initialized with no update XML
def get_from_name_and_so(self, line): def get_from_name_and_so(self, line):
@ -35,13 +34,16 @@ class AccountMoveCompletionRule(models.Model):
...} ...}
""" """
res = {} res = {}
so_obj = self.env['sale.order'] so_obj = self.env["sale.order"]
orders = so_obj.search([('name', '=', line.name)]) orders = so_obj.search([("name", "=", line.name)])
if len(orders) > 1: if len(orders) > 1:
raise ErrorTooManyPartner( raise ErrorTooManyPartner(
_('Line named "%s" was matched by more ' _(
'than one partner while looking on SO by ref.') % 'Line named "%s" was matched by more '
line.name) "than one partner while looking on SO by ref."
)
% line.name
)
if len(orders) == 1: if len(orders) == 1:
res['partner_id'] = orders[0].partner_id.id res["partner_id"] = orders[0].partner_id.id
return res return res

View File

@ -5,66 +5,91 @@ from odoo.tests.common import SavepointCase
class TestCompliteSO(SavepointCase): class TestCompliteSO(SavepointCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.partner = cls.env.ref('base.res_partner_1') cls.partner = cls.env.ref("base.res_partner_1")
p = cls.env.ref('product.product_product_6') p = cls.env.ref("product.product_product_6")
cls.order = cls.env['sale.order'].create({ cls.order = cls.env["sale.order"].create(
'name': 'Test order', {
'partner_id': cls.partner.id, "name": "Test order",
'order_line': [(0, 0, {'name': 'Test autocomplet', "partner_id": cls.partner.id,
'product_id': p.id, "order_line": [
'product_uom_qty': 2, (
'qty_to_invoice': 2, 0,
'qty_delivered': 2, 0,
'product_uom': p.uom_id.id, {
'price_unit': p.list_price})], "name": "Test autocomplet",
}) "product_id": p.id,
rule_ids = cls.env.ref('account_move_base_import.' "product_uom_qty": 2,
'bank_statement_completion_rule_5') "qty_to_invoice": 2,
rule_ids += cls.env.ref('account_move_base_import.' "qty_delivered": 2,
'bank_statement_completion_rule_4') "product_uom": p.uom_id.id,
rule_ids += cls.env.ref('account_move_base_import.' "price_unit": p.list_price,
'bank_statement_completion_rule_3') },
rule_ids += cls.env.ref('account_move_base_import.' )
'bank_statement_completion_rule_2') ],
rule_ids += cls.env.ref('account_move_so_import.' }
'bank_statement_completion_rule_1') )
# create journal with profile rule_ids = cls.env.ref(
cls.journal = cls.env['account.journal'].create({ "account_move_base_import." "bank_statement_completion_rule_5"
'name': 'Company Bank journal', )
'type': 'bank', rule_ids += cls.env.ref(
'code': 'BNKFB', "account_move_base_import." "bank_statement_completion_rule_4"
'rule_ids': [ )
(4, comp_rule.id, False) for comp_rule in rule_ids rule_ids += cls.env.ref(
], "account_move_base_import." "bank_statement_completion_rule_3"
'used_for_completion': True, )
}) rule_ids += cls.env.ref(
cls.move = cls.env['account.move'].create( "account_move_base_import." "bank_statement_completion_rule_2"
{'name': 'Test move', 'journal_id': cls.journal.id} )
rule_ids += cls.env.ref(
"account_move_so_import." "bank_statement_completion_rule_1"
)
# create journal with profile
cls.journal = cls.env["account.journal"].create(
{
"name": "Company Bank journal",
"type": "bank",
"code": "BNKFB",
"rule_ids": [(4, comp_rule.id, False) for comp_rule in rule_ids],
"used_for_completion": True,
}
)
cls.move = cls.env["account.move"].create(
{"name": "Test move", "journal_id": cls.journal.id}
)
cls.account_payable = cls.env["account.account"].search(
[
(
"user_type_id",
"=",
cls.env.ref("account.data_account_type_payable").id,
),
],
limit=1,
) )
cls.account_payable = cls.env['account.account'].search([
('user_type_id', '=',
cls.env.ref('account.data_account_type_payable').id),
], limit=1)
def test_completion_so(self): def test_completion_so(self):
self.order.action_confirm() self.order.action_confirm()
aml = self.env['account.move.line'].create( aml = self.env["account.move.line"].create(
{ {
'name': self.order.name, "name": self.order.name,
'account_id': self.account_payable.id, "account_id": self.account_payable.id,
'move_id': self.move.id, "move_id": self.move.id,
'credit': 0.0, "credit": 0.0,
}
)
aml.with_context(check_move_validity=False).write(
{
"credit": 1,
} }
) )
aml.with_context(check_move_validity=False).write({
'credit': 1,
})
self.assertFalse(self.move.partner_id) self.assertFalse(self.move.partner_id)
self.move.button_auto_completion() self.move.button_auto_completion()
self.assertEqual(self.move.partner_id, self.partner,) self.assertEqual(
self.move.partner_id,
self.partner,
)

View File

@ -0,0 +1 @@
../../../../account_move_so_import

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)