product_analytic_donation: black, isort, etc.

14.0
Alexis de Lattre 3 years ago
parent 32977c086f
commit 8f3fbf3ca4

@ -3,15 +3,15 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Product Analytic Donation',
'version': '14.0.1.0.0',
'category': 'Donation',
'license': 'AGPL-3',
'summary': 'Glue module between donation and product_analytic',
'author': 'Akretion, Odoo Community Association (OCA)',
'maintainers': ['alexis-via'],
'website': 'https://github.com/OCA/donation',
'depends': ['donation', 'product_analytic'],
'auto_install': True,
'installable': True,
"name": "Product Analytic Donation",
"version": "14.0.1.0.0",
"category": "Donation",
"license": "AGPL-3",
"summary": "Glue module between donation and product_analytic",
"author": "Akretion, Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
"website": "https://github.com/OCA/donation",
"depends": ["donation", "product_analytic"],
"auto_install": True,
"installable": True,
}

@ -6,24 +6,25 @@ from odoo import api, models
class DonationLine(models.Model):
_inherit = 'donation.line'
_inherit = "donation.line"
@api.onchange('product_id')
@api.onchange("product_id")
def product_id_change(self):
res = super(DonationLine, self).product_id_change()
if self.product_id:
ana_accounts = self.product_id.product_tmpl_id.\
_get_product_analytic_accounts()
ana_account = ana_accounts['income']
ana_accounts = (
self.product_id.product_tmpl_id._get_product_analytic_accounts()
)
ana_account = ana_accounts["income"]
if ana_account:
self.analytic_account_id = ana_account.id
return res
@api.model
def create(self, vals):
if vals.get('product_id') and not vals.get('analytic_account_id'):
product = self.env['product.product'].browse(vals['product_id'])
if vals.get("product_id") and not vals.get("analytic_account_id"):
product = self.env["product.product"].browse(vals["product_id"])
ana_accounts = product.product_tmpl_id._get_product_analytic_accounts()
ana_account = ana_accounts['income']
vals['analytic_account_id'] = ana_account.id or False
ana_account = ana_accounts["income"]
vals["analytic_account_id"] = ana_account.id or False
return super().create(vals)

@ -5,25 +5,29 @@ from odoo.tests.common import TransactionCase
class TestDonationLine(TransactionCase):
def setUp(self):
super(TestDonationLine, self).setUp()
self.product1 = self.env['product.product'].create({
'name': 'test product 01',
})
self.analytic_account1 = self.env['account.analytic.account'].create({
'name': 'test analytic_account1'})
self.analytic_account2 = self.env['account.analytic.account'].create({
'name': 'test analytic_account2'})
self.product2 = self.env['product.product'].create({
'name': 'test product 02',
'income_analytic_account_id': self.analytic_account1.id,
'expense_analytic_account_id': self.analytic_account2.id,
})
self.journal = self.env['account.journal'].create({
'name': 'Test journal',
'code': 'TEST',
'type': 'bank'})
self.product1 = self.env["product.product"].create(
{
"name": "test product 01",
}
)
self.analytic_account1 = self.env["account.analytic.account"].create(
{"name": "test analytic_account1"}
)
self.analytic_account2 = self.env["account.analytic.account"].create(
{"name": "test analytic_account2"}
)
self.product2 = self.env["product.product"].create(
{
"name": "test product 02",
"income_analytic_account_id": self.analytic_account1.id,
"expense_analytic_account_id": self.analytic_account2.id,
}
)
self.journal = self.env["account.journal"].create(
{"name": "Test journal", "code": "TEST", "type": "bank"}
)
self.payment_mode = self.env["account.payment.mode"].create(
{
"name": "test_payment_mode",
@ -35,18 +39,24 @@ class TestDonationLine(TransactionCase):
).id,
}
)
self.donation = self.env['donation.donation'].create({
'partner_id': self.env.ref('donation_base.donor1').id,
'donation_date': '2021-07-21',
'payment_mode_id': self.payment_mode.id,
'line_ids': [
(0, 0, {
'quantity': 1,
'unit_price': 50,
'product_id': self.product1.id,
})
]
})
self.donation = self.env["donation.donation"].create(
{
"partner_id": self.env.ref("donation_base.donor1").id,
"donation_date": "2021-07-21",
"payment_mode_id": self.payment_mode.id,
"line_ids": [
(
0,
0,
{
"quantity": 1,
"unit_price": 50,
"product_id": self.product1.id,
},
)
],
}
)
self.donation_line = self.donation.line_ids[0]
def test_onchange_product_id(self):
@ -54,21 +64,30 @@ class TestDonationLine(TransactionCase):
self.donation_line.product_id_change()
self.assertEqual(
self.donation_line.analytic_account_id.id,
self.product2.income_analytic_account_id.id)
self.product2.income_analytic_account_id.id,
)
def test_create(self):
donation2 = self.env['donation.donation'].create({
'partner_id': self.env.ref('donation_base.donor1').id,
'donation_date': '2017-07-20',
'payment_mode_id': self.payment_mode.id,
'line_ids': [
(0, 0, {
'quantity': 1,
'unit_price': 50,
'product_id': self.product2.id,
})
]
})
donation2 = self.env["donation.donation"].create(
{
"partner_id": self.env.ref("donation_base.donor1").id,
"donation_date": "2017-07-20",
"payment_mode_id": self.payment_mode.id,
"line_ids": [
(
0,
0,
{
"quantity": 1,
"unit_price": 50,
"product_id": self.product2.id,
},
)
],
}
)
donation_line2 = donation2.line_ids[0]
self.assertEqual(donation_line2.analytic_account_id.id,
self.product2.income_analytic_account_id.id)
self.assertEqual(
donation_line2.analytic_account_id.id,
self.product2.income_analytic_account_id.id,
)

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