[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
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
{
'name': "Journal Entry Sale Order completion",
'version': '12.0.1.0.0',
'author': "Camptocamp,Odoo Community Association (OCA)",
'maintainer': 'Camptocamp',
'category': 'Finance',
'complexity': 'easy',
'depends': ['account_move_base_import', 'sale'],
'website': 'http://www.camptocamp.com',
'data': [
'data/completion_rule_data.xml',
"name": "Journal Entry Sale Order completion",
"version": "12.0.1.0.0",
"author": "Camptocamp,Odoo Community Association (OCA)",
"maintainer": "Camptocamp",
"category": "Finance",
"complexity": "easy",
"depends": ["account_move_base_import", "sale"],
"website": "https://github.com/OCA/account-reconcile",
"data": [
"data/completion_rule_data.xml",
],
'installable': True,
'auto_install': False,
'license': 'AGPL-3',
"installable": True,
"auto_install": False,
"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">
<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
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from . import account_move

View File

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

View File

@ -5,66 +5,91 @@ from odoo.tests.common import SavepointCase
class TestCompliteSO(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.partner = cls.env.ref('base.res_partner_1')
p = cls.env.ref('product.product_product_6')
cls.order = cls.env['sale.order'].create({
'name': 'Test order',
'partner_id': cls.partner.id,
'order_line': [(0, 0, {'name': 'Test autocomplet',
'product_id': p.id,
'product_uom_qty': 2,
'qty_to_invoice': 2,
'qty_delivered': 2,
'product_uom': p.uom_id.id,
'price_unit': p.list_price})],
})
rule_ids = cls.env.ref('account_move_base_import.'
'bank_statement_completion_rule_5')
rule_ids += cls.env.ref('account_move_base_import.'
'bank_statement_completion_rule_4')
rule_ids += cls.env.ref('account_move_base_import.'
'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
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.partner = cls.env.ref("base.res_partner_1")
p = cls.env.ref("product.product_product_6")
cls.order = cls.env["sale.order"].create(
{
"name": "Test order",
"partner_id": cls.partner.id,
"order_line": [
(
0,
0,
{
"name": "Test autocomplet",
"product_id": p.id,
"product_uom_qty": 2,
"qty_to_invoice": 2,
"qty_delivered": 2,
"product_uom": p.uom_id.id,
"price_unit": p.list_price,
},
)
],
}
)
rule_ids = cls.env.ref(
"account_move_base_import." "bank_statement_completion_rule_5"
)
rule_ids += cls.env.ref(
"account_move_base_import." "bank_statement_completion_rule_4"
)
rule_ids += cls.env.ref(
"account_move_base_import." "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
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):
self.order.action_confirm()
aml = self.env['account.move.line'].create(
aml = self.env["account.move.line"].create(
{
'name': self.order.name,
'account_id': self.account_payable.id,
'move_id': self.move.id,
'credit': 0.0,
"name": self.order.name,
"account_id": self.account_payable.id,
"move_id": self.move.id,
"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.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,
)