[IMP] Set Auto install true and change configuration view, change test cases, solved flake8 and pep8

This commit is contained in:
Haresh Chavda 2018-01-18 16:08:21 +05:30
parent 9985810340
commit aba1a60084
12 changed files with 150 additions and 51 deletions

View File

@ -15,14 +15,14 @@
'security/ir.model.access.csv',
'data/account_discount_data.xml',
'views/account_invoice_views.xml',
'views/res_config_settings_views.xml',
'views/discount_config_view.xml',
'views/res_config_settings_views.xml',
'report/report_menu.xml',
'report/custom_invoice_report.xml',
],
'demo':[
'demo': [
'demo/discount_config_demo.xml',
],
'installable': True,
'auto_install': False,
'auto_install': True,
}

View File

@ -103,13 +103,15 @@ class AccountInvoice(models.Model):
config_id = self.env[
'res.config.settings'].search([], order='id desc', limit=1)
if config_id and config_id.global_discount_invoice_apply:
if config_id.global_discount_percentage_invoice < self.discount_per:
global_percentage = config_id.global_discount_percentage_invoice
if global_percentage < self.discount_per:
raise Warning(_("You are not allowed to apply Discount "
"Percentage(%s) more than configured Discount"
" Percentage (%s) in configuration setting!"
) % (
formatLang(self.env, self.discount_per, digits=2),
formatLang(self.env, config_id.global_discount_percentage_invoice,
formatLang(self.env,
config_id.global_discount_percentage_invoice,
digits=2)))
@api.onchange('discount_amount')
@ -134,10 +136,12 @@ class AccountInvoice(models.Model):
config_id = self.env[
'res.config.settings'].search([], order='id desc', limit=1)
if config_id and config_id.global_discount_invoice_apply:
if config_id.global_discount_fix_invoice_amount < self.discount_amount:
fix_amount = config_id.global_discount_fix_invoice_amount
if fix_amount < self.discount_amount:
raise Warning(_("You're not allowed to apply this amount of"
" discount as discount Amount (%s) is greater"
" than Configuration Amount (%s).") % (
formatLang(self.env, self.discount, digits=2),
formatLang(self.env, config_id.global_discount_fix_invoice_amount,
formatLang(self.env,
config_id.global_discount_fix_invoice_amount,
digits=2)))

View File

@ -24,13 +24,15 @@ class AccountDiscountConfig(models.Model):
def _check_fix_amount_value(self):
config_id = self.env['res.config.settings'].search(
[], order='id desc', limit=1)
fix_amount = config_id.global_discount_fix_invoice_amount
if config_id and config_id.global_discount_invoice_apply \
and config_id.global_discount_fix_invoice_amount < self.fix_amount:
and fix_amount < self.fix_amount:
raise ValueError(
_("Fix amount (%s) is greater than configuration Amount (%s)!"
) % (formatLang(
self.env, self.fix_amount, digits=2), formatLang(
self.env, config_id.global_discount_fix_invoice_amount, digits=2)))
) % (formatLang(self.env, self.fix_amount, digits=2),
formatLang(self.env,
config_id.global_discount_fix_invoice_amount,
digits=2)))
@api.constrains('percentage')
def _check_percentage(self):
@ -38,12 +40,13 @@ class AccountDiscountConfig(models.Model):
raise ValueError(_("Percentage should be between 0% to 100%!"))
config_id = self.env[
'res.config.settings'].search([], order='id desc', limit=1)
percentage = config_id.global_discount_percentage_invoice
if config_id and config_id.global_discount_invoice_apply \
and config_id.global_discount_percentage_invoice < self.percentage:
and percentage < self.percentage:
raise ValueError(
_("Percentage (%s) is greater than configuration Percentage "
"(%s)!") % (formatLang(
self.env, self.percentage, digits=2),
"(%s)!") % (
formatLang(self.env, self.percentage, digits=2),
formatLang(self.env,
config_id.global_discount_percentage_invoice,
digits=2)))

View File

@ -20,3 +20,40 @@ class TestDiscountCommon(TransactionCase):
'fix_amount': 3000.0,
'percentage': 20.0,
})
ir_model_data_obj = self.env['ir.model.data']
account_acccount_obj = self.env['account.account']
journal_obj = self.env['account.journal']
company_id = \
ir_model_data_obj.xmlid_to_res_id('base.main_company') or False
user_type_payable_id = ir_model_data_obj.xmlid_to_res_id(
'account.data_account_type_payable')
user_type_receivable_id = ir_model_data_obj.xmlid_to_res_id(
'account.data_account_type_receivable')
self.user_type_revenue_id = ir_model_data_obj.xmlid_to_res_id(
'account.data_account_type_revenue')
self.account_type_payable_id = account_acccount_obj.create({
'name': 'Test Payable Account',
'code': 'TestPA',
'reconcile': True,
'user_type_id': user_type_payable_id})
self.account_type_receivable_id = account_acccount_obj.create({
'name': 'Test Reiceivable Account',
'code': 'TestRA',
'reconcile': True,
'user_type_id': user_type_receivable_id})
self.partner_id = self.env['res.partner'].create({
'name': 'Test Partner',
'property_account_receivable_id':
self.account_type_receivable_id.id,
'email': 'testpartner@test.com',
})
self.journal_id = journal_obj.create({
'name': 'Test Journal',
'code': 'Journal001',
'type': 'sale',
'company_id': company_id})

View File

@ -4,24 +4,27 @@ from .discount_common import TestDiscountCommon
import logging
import time
class TestInvoiceDiscount(TestDiscountCommon):
def setUp(self):
super(TestInvoiceDiscount, self).setUp()
def discount_01_set_fixamount(self):
self.account_id = self.env['account.account'].create({
'name': 'Test',
'code': 'DA',
'user_type_id':self.env.ref("account.data_account_type_revenue").id,
'user_type_id': self.user_type_revenue_id,
})
invoice_id = self.env['account.invoice'].create({
'name': 'Discount Invoice Test Fixed',
'partner_id': self.env.ref("base.res_partner_4").id,
'partner_id': self.partner_id.id,
'currency_id': self.env.ref('base.USD').id,
'account_id': self.account_id.id,
'type': 'out_invoice',
'date_invoice': time.strftime('%Y') + '-03-12',
'journal_id': self.journal_id.id,
})
invoice_id.onchange_discount_method()
invoice_id.write({
@ -56,17 +59,18 @@ class TestInvoiceDiscount(TestDiscountCommon):
self.account_id = self.env['account.account'].create({
'name': 'Test',
'code': 'DA',
'user_type_id':self.env.ref("account.data_account_type_revenue").id,
'user_type_id': self.user_type_revenue_id,
})
invoice_id = self.env['account.invoice'].create({
'name': 'Discount Invoice Test',
'partner_id': self.env.ref("base.res_partner_4").id,
'partner_id': self.partner_id.id,
'currency_id': self.env.ref('base.USD').id,
'account_id': self.account_id.id,
'type': 'out_invoice',
'discount_method': 'per',
'discount_per': 10,
'date_invoice': time.strftime('%Y') + '-03-12',
'journal_id': self.journal_id.id,
})
self.env['account.invoice.line'].create({
'product_id': self.env.ref("product.product_product_10").id,

View File

@ -3,6 +3,7 @@
from .test_01_account_discount import TestInvoiceDiscount
import logging
class TestDiscountInvoice(TestInvoiceDiscount):
def setUp(self):
super(TestDiscountInvoice, self).setUp()

View File

@ -36,6 +36,11 @@
<field name="global_discount_percentage_invoice" attrs="{'required': [('global_discount_invoice_apply', '=', True)]}"/>
</div>
</div>
<div class="content-group" attrs="{'invisible': [('global_discount_invoice_apply','=',False)]}">
<div class="mt16">
<button name="%(account_discount.action_account_discount_config)d" icon="fa-arrow-right" type="action" string="Group Leval Discount Configuration" class="btn-link"/>
</div>
</div>
</div>
</div>
</div>

View File

@ -10,12 +10,12 @@
'author': 'FlectraHQ',
'website': 'https://flectrahq.com',
'version': '1.0',
'depends': ['sale_management', 'sale_stock', 'account_discount'],
'depends': ['sale_management', 'account_discount'],
'data': [
'security/ir.model.access.csv',
'data/sale_discount_data.xml',
'views/res_config_settings_views.xml',
'views/sale_discount_config_view.xml',
'views/res_config_settings_views.xml',
'views/sale_view.xml',
'report/sale_order_report_view.xml',
],
@ -23,5 +23,5 @@
'demo/sale_order.xml',
],
'installable': True,
'auto_install': False,
'auto_install': True,
}

View File

@ -20,11 +20,52 @@ class TestDiscountCommon(TransactionCase):
'fix_amount': 3000.0,
'percentage': 20.0,
})
self.partner_id = self.env.ref('base.res_partner_3')
self.partner_invoice_id = self.env.ref('base.res_partner_address_11')
journal_obj = self.env['account.journal']
ir_model_data_obj = self.env['ir.model.data']
self.user_id = self.env.ref('base.user_root')
self.partner_shipping_id = self.env.ref('base.res_partner_address_11')
self.pricelist_id = self.env.ref('product.list0')
self.product_1 = self.env.ref('product.product_delivery_01')
self.product_1 = \
self.env.ref('product.product_order_01').product_tmpl_id
self.product_uom = self.env.ref('product.product_uom_unit')
self.product_2 = self.env.ref('product.product_product_25')
self.product_2 = \
self.env.ref('product.service_order_01').product_tmpl_id
self.SaleOrderLine = self.env['sale.order.line']
self.SaleOrder = self.env['sale.order']
account_acccount_obj = self.env['account.account']
company_id = \
ir_model_data_obj.xmlid_to_res_id('base.main_company') or False
user_type_payable_id = ir_model_data_obj.xmlid_to_res_id(
'account.data_account_type_payable')
user_type_receivable_id = ir_model_data_obj.xmlid_to_res_id(
'account.data_account_type_receivable')
self.user_type_revenue_id = ir_model_data_obj.xmlid_to_res_id(
'account.data_account_type_revenue')
self.account_type_payable_id = account_acccount_obj.create({
'name': 'Test Payable Account',
'code': 'TestPA',
'reconcile': True,
'user_type_id': user_type_payable_id})
self.account_type_receivable_id = account_acccount_obj.create({
'name': 'Test Reiceivable Account',
'code': 'TestRA',
'reconcile': True,
'user_type_id': user_type_receivable_id})
self.partner_id = self.env['res.partner'].create({
'name': 'Test Partner',
'property_account_receivable_id':
self.account_type_receivable_id.id,
'email': 'testpartner@test.com',
})
self.journal_id = journal_obj.create({
'name': 'Test Sales Discount Journal ',
'code': 'JournalSD',
'type': 'sale',
'company_id': company_id
})
self.product_1.write({
'property_account_income_id': self.account_type_receivable_id.id})
self.product_2.write({
'property_account_income_id': self.account_type_receivable_id.id})

View File

@ -1,7 +1,6 @@
# Part of Flectra See LICENSE file for full copyright and licensing details.
from .discount_common import TestDiscountCommon
import logging
class TestSODiscount(TestDiscountCommon):
@ -9,14 +8,12 @@ class TestSODiscount(TestDiscountCommon):
super(TestSODiscount, self).setUp()
def discount_01_set_fixamount(self):
sale_order = self.env['sale.order'].create({
sale_order = self.SaleOrder.create({
'partner_id': self.partner_id.id,
'partner_invoice_id': self.partner_invoice_id.id,
'partner_shipping_id': self.partner_shipping_id.id,
'pricelist_id': self.pricelist_id.id,
})
sale_order.onchange_discount_method()
self.env['sale.order.line'].create({
self.SaleOrderLine.create({
'name': self.product_1.name,
'product_id': self.product_1.id,
'product_uom_qty': 20,
@ -24,7 +21,7 @@ class TestSODiscount(TestDiscountCommon):
'price_unit': self.product_1.list_price,
'order_id': sale_order.id,
})
self.env['sale.order.line'].create({
self.SaleOrderLine.create({
'name': self.product_2.name,
'product_id': self.product_2.id,
'product_uom_qty': 20,
@ -36,16 +33,11 @@ class TestSODiscount(TestDiscountCommon):
'discount_method': 'fixed',
'discount_amount': 100,
})
self.assertTrue(sale_order, 'Sale Order: no sale order created')
logging.info('Successful: Sale Order Created!')
sale_order.calculate_discount()
return sale_order
def discount_02_set_percentages(self):
sale_order = self.env['sale.order'].create({
sale_order = self.SaleOrder.create({
'partner_id': self.partner_id.id,
'partner_invoice_id': self.partner_invoice_id.id,
'partner_shipping_id': self.partner_shipping_id.id,
'pricelist_id': self.pricelist_id.id,
})
sale_order.onchange_discount_method()
@ -53,7 +45,7 @@ class TestSODiscount(TestDiscountCommon):
'discount_method': 'per',
'discount_per': 10,
})
self.env['sale.order.line'].create({
self.SaleOrderLine.create({
'name': self.product_1.name,
'product_id': self.product_1.id,
'product_uom_qty': 10,
@ -62,7 +54,7 @@ class TestSODiscount(TestDiscountCommon):
'order_id': sale_order.id,
'discount': 10,
})
self.env['sale.order.line'].create({
self.SaleOrderLine.create({
'name': self.product_2.name,
'product_id': self.product_2.id,
'product_uom_qty': 20,
@ -71,9 +63,6 @@ class TestSODiscount(TestDiscountCommon):
'order_id': sale_order.id,
'discount': 10,
})
self.assertTrue(sale_order, 'Sale Order: no sale order created')
logging.info('Successful: Sale Order Created!')
sale_order.calculate_discount()
sale_order.write({
'discount_method': 'per',
'discount_per': 20.0,

View File

@ -1,6 +1,7 @@
# Part of Flectra See LICENSE file for full copyright and licensing details.
from .test_01_sale_order_discount import TestSODiscount
import logging
class TestSODiscountInvoice(TestSODiscount):
@ -8,10 +9,19 @@ class TestSODiscountInvoice(TestSODiscount):
super(TestSODiscountInvoice, self).setUp()
def test_01_so_dp_fixed_amount(self):
so = self.discount_01_set_fixamount()
so._prepare_invoice()
sale_order = self.discount_01_set_fixamount()
self.assertTrue(sale_order, 'Sale Order: no sale order created')
logging.info('Successful: Sale Order Created!')
sale_order.calculate_discount()
sale_order.order_line._compute_product_updatable()
sale_order.action_confirm()
sale_order.action_invoice_create()
def test_02_so_percentage_discount(self):
so = self.discount_02_set_percentages()
so._prepare_invoice()
sale_order = self.discount_02_set_percentages()
self.assertTrue(sale_order, 'Sale Order: no sale order created')
logging.info('Successful: Sale Order Created!')
sale_order.calculate_discount()
sale_order.order_line._compute_product_updatable()
sale_order.action_confirm()
sale_order.action_invoice_create()

View File

@ -36,6 +36,11 @@
<field name="global_discount_percentage" attrs="{'required': [('global_discount_apply', '=', True)]}"/>
</div>
</div>
<div class="content-group" attrs="{'invisible': [('global_discount_apply','=',False)]}">
<div class="mt16">
<button name="%(sales_discount.action_sale_discount_config)d" icon="fa-arrow-right" type="action" string="Group Leval Discount Configuration" class="btn-link"/>
</div>
</div>
</div>
</div>
</div>