def test_0010_render_report_xhtml(self): ''' Render the report without PDF conversion ''' UserReport = POOL.get('res.user', type='report') IRReport = POOL.get('ir.action.report') with Transaction().start(DB_NAME, USER, context=CONTEXT): self.setup_defaults() with Transaction().set_context(company=self.company.id): report_html, = IRReport.create([{ 'name': 'HTML Report', 'model': 'res.user', 'report_name': 'res.user', 'report_content': buffer( '<h1>Hello, {{records[0].name}}!</h1>' ), 'extension': 'html', }]) val = UserReport.execute([USER], {}) self.assertEqual(val[0], u'html') self.assertEqual( str(val[1]), '<h1>Hello, Administrator!</h1>' )
def _create_coa_minimal(self, company): """Create a minimal chart of accounts """ AccountTemplate = POOL.get('account.account.template') Account = POOL.get('account.account') account_create_chart = POOL.get( 'account.create_chart', type="wizard" ) account_template, = AccountTemplate.search( [('parent', '=', None)] ) session_id, _, _ = account_create_chart.create() create_chart = account_create_chart(session_id) create_chart.account.account_template = account_template create_chart.account.company = company create_chart.transition_create_account() receivable, = Account.search([ ('kind', '=', 'receivable'), ('company', '=', company), ]) payable, = Account.search([ ('kind', '=', 'payable'), ('company', '=', company), ]) create_chart.properties.company = company create_chart.properties.account_receivable = receivable create_chart.properties.account_payable = payable create_chart.transition_create_properties()
def test_0200_translation_clean(self): """ Check if the cleaning of translations work """ TranslationSet = POOL.get('ir.translation.set', type='wizard') TranslationClean = POOL.get('ir.translation.clean', type='wizard') IRTranslation = POOL.get('ir.translation') IRModule = POOL.get('ir.module.module') with Transaction().start(DB_NAME, USER, CONTEXT): # First create all the translations session_id, _, _ = TranslationSet.create() set_wizard = TranslationSet(session_id) set_wizard.transition_set_() # Uninstall nereid_test and there should be no translations # belonging to that module with type as nereid or # nereid_template nereid_test, = IRModule.search([('name', '=', 'nereid_test')]) nereid_test.state = 'uninstalled' nereid_test.save() session_id, _, _ = TranslationClean.create() clean_wizard = TranslationClean(session_id) clean_wizard.transition_clean() count = IRTranslation.search([ ('module', '=', 'nereid_test'), ('type', 'in', ('nereid', 'nereid_template')) ], count=True) self.assertEqual(count, 0)
def setUp(self): trytond.tests.test_tryton.install_module('nereid_s3') self.static_file = POOL.get('nereid.static.file') self.static_folder = POOL.get('nereid.static.folder') # Mock S3Connection self.s3_api_patcher = patch( 'boto.s3.connection.S3Connection', autospec=True ) PatchedS3 = self.s3_api_patcher.start() # Mock S3Key self.s3_key_patcher = patch( 'boto.s3.key.Key', autospec=True ) PatchedS3Key = self.s3_key_patcher.start() PatchedS3.return_value = connection.S3Connection('ABCD', '123XYZ') PatchedS3.return_value.get_bucket = lambda bucket_name: Bucket( PatchedS3.return_value, 'tryton-test-s3' ) PatchedS3Key.return_value = Key( Bucket(PatchedS3.return_value, 'tryton-test-s3'), 'some key' ) PatchedS3Key.return_value.key = "some key" PatchedS3Key.return_value.get_contents_as_string = lambda *a: 'testfile' PatchedS3Key.return_value.set_contents_from_string = \ lambda value: 'testfile'
def test_0300_translation_update(self): """ Check if the update does not break this functionality """ TranslationSet = POOL.get('ir.translation.set', type='wizard') TranslationUpdate = POOL.get('ir.translation.update', type='wizard') IRTranslation = POOL.get('ir.translation') IRLanguage = POOL.get('ir.lang') with Transaction().start(DB_NAME, USER, CONTEXT): # First create all the translations session_id, _, _ = TranslationSet.create() set_wizard = TranslationSet(session_id) set_wizard.transition_set_() # set an additional language as translatable new_lang, = IRLanguage.search([ ('translatable', '=', False) ], limit=1) new_lang.translatable = True new_lang.save() count_before = IRTranslation.search([], count=True) # Now update the translations session_id, _, _ = TranslationUpdate.create() update_wizard = TranslationUpdate(session_id) update_wizard.start.language = new_lang update_wizard.do_update(update_wizard.update.get_action()) # check the count now count_after = IRTranslation.search([], count=True) self.assertEqual(count_after, count_before * 2)
def setUp(self): install_module('test') self.one2many = POOL.get('test.copy.one2many') self.one2many_target = POOL.get('test.copy.one2many.target') self.one2many_reference = POOL.get('test.copy.one2many_reference') self.one2many_reference_target = \ POOL.get('test.copy.one2many_reference.target')
def test_0090_import_sale_order_with_bundle_product_check_duplicate(self): """ Tests import of sale order with bundle product using magento data This tests that the duplication of BoMs doesnot happen """ Sale = POOL.get('sale.sale') ProductTemplate = POOL.get('product.template') Category = POOL.get('product.category') MagentoOrderState = POOL.get('magento.order_state') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view.id, 'magento_website': self.website1.id, }): MagentoOrderState.create_all_using_magento_data( load_json('order-states', 'all'), ) category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) order_data = load_json('orders', '300000001') with patch( 'magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context({'company': self.company.id}): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True ): Sale.find_or_create_using_magento_data(order_data) # There should be a BoM for the bundle product product_template = \ ProductTemplate.find_or_create_using_magento_id(158) product = product_template.products[0] self.assertTrue(len(product.boms), 1) self.assertTrue(len(product.boms[0].bom.inputs), 2) order_data = load_json('orders', '300000001-a') # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): Sale.find_or_create_using_magento_data(order_data) # There should be a BoM for the bundle product product_template = \ ProductTemplate.find_or_create_using_magento_id( 158 ) self.assertEqual(len(product.boms), 1) self.assertEqual(len(product.boms[0].bom.inputs), 2)
def test_0400_translation_export(self): """ Export the translations and test """ TranslationSet = POOL.get('ir.translation.set', type='wizard') TranslationUpdate = POOL.get('ir.translation.update', type='wizard') IRTranslation = POOL.get('ir.translation') IRLanguage = POOL.get('ir.lang') with Transaction().start(DB_NAME, USER, CONTEXT): # First create all the translations session_id, _, _ = TranslationSet.create() set_wizard = TranslationSet(session_id) set_wizard.transition_set_() # set an additional language as translatable new_lang, = IRLanguage.search([ ('translatable', '=', False) ], limit=1) new_lang.translatable = True new_lang.save() # Now update the translations session_id, _, _ = TranslationUpdate.create() update_wizard = TranslationUpdate(session_id) update_wizard.start.language = new_lang update_wizard.do_update(update_wizard.update.get_action()) # TODO: Check the contents of the po file IRTranslation.translation_export(new_lang.code, 'nereid_test') IRTranslation.translation_export(new_lang.code, 'nereid')
def test0030_get_variant_images(self): """ Test to get variant images. If boolean field use_template_images is true return images of product template else return images of variant """ Product = POOL.get('product.product') StaticFolder = POOL.get("nereid.static.folder") StaticFile = POOL.get("nereid.static.file") with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() folder, = StaticFolder.create([{ 'name': 'Test' }]) file_buffer = buffer('test-content') file = StaticFile.create([{ 'name': 'test.png', 'folder': folder.id, 'file_binary': file_buffer }])[0] file1 = StaticFile.create([{ 'name': 'test1.png', 'folder': folder.id, 'file_binary': file_buffer }])[0] uom, = self.Uom.search([], limit=1) # creating product template product_template, = self.Template.create([{ 'name': 'test template', 'category': self.category.id, 'type': 'goods', 'list_price': Decimal('10'), 'cost_price': Decimal('5'), 'default_uom': uom.id, 'description': 'Description of template', 'media': [('create', [{ 'static_file': file.id, }])], 'products': [('create', self.Template.default_products())] }]) product, = product_template.products Product.write([product], { 'media': [('create', [{ 'static_file': file1.id, }])] }) self.assertEqual(product.get_images()[0].id, file.id) Product.write([product], { 'use_template_images': False, }) self.assertEqual(product.get_images()[0].id, file1.id)
def setUp(self): super(CompanyTestCase, self).setUp() self.party = POOL.get('party.party') self.company = POOL.get('company.company') self.employee = POOL.get('company.employee') self.currency = POOL.get('currency.currency') self.user = POOL.get('res.user')
def setUp(self): trytond.tests.test_tryton.install_module('company') self.party = POOL.get('party.party') self.company = POOL.get('company.company') self.employee = POOL.get('company.employee') self.currency = POOL.get('currency.currency') self.user = POOL.get('res.user')
def test_0080_export_product_stock_information(self): """ This test checks if the method to call for updation of product stock info does not break anywhere in between. This method does not check the API calls """ Product = POOL.get('product.product') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, 'company': self.company.id, }): category_data = load_json('categories', '17') Category.create_using_magento_data(category_data) product_data = load_json('products', '135') Product.find_or_create_using_magento_data( product_data ) with patch( 'magento.Inventory', mock_inventory_api(), create=True ): self.channel1.export_inventory()
def setUp(self): super(BaseTestCheckout, self).setUp() trytond.tests.test_tryton.install_module("nereid_shipping") trytond.tests.test_tryton.install_module("shipping_ups") self.Carrier = POOL.get("carrier") self.Category = POOL.get("product.category") self.Account = POOL.get("account.account") self.ProductTemplate = POOL.get("product.template") self.UPSService = POOL.get("ups.service") self.templates.update( { "checkout/signin.jinja": "{{form.errors|safe}}", "checkout/signin-email-in-use.jinja": "{{email}} in use", "checkout/shipping_address.jinja": "{{address_form.errors|safe}}", "checkout/billing_address.jinja": "{{address_form.errors|safe}}", "checkout/delivery_method.jinja": "{{delivery_rates|map(attribute=4)|list|tojson|safe}}", "checkout/payment_method.jinja": """[ {{payment_form.errors|safe}}, {{credit_card_form.errors|safe}}, ]""", "emails/sale-confirmation-text.jinja": " ", "emails/sale-confirmation-html.jinja": " ", "checkout.jinja": "{{form.errors|safe}}", "sale.jinja": " ", "sales.jinja": """{{request.args.get('filter_by')}} {% for sale in sales %}#{{sale.id}}{% endfor %} """, } ) # Patch SMTP Lib self.smtplib_patcher = patch("smtplib.SMTP") self.PatchedSMTP = self.smtplib_patcher.start()
def test0030_menuitem(self): ''' Test create menuitem for products ''' self.Product = POOL.get('product.product') self.Template = POOL.get('product.template') with Transaction().start(DB_NAME, USER, context=CONTEXT): app = self.get_app() self.setup_defaults() uom, = self.Uom.search([], limit=1) template, = self.Template.create([{ 'name': 'TestProduct', 'type': 'goods', 'list_price': Decimal('100'), 'cost_price': Decimal('100'), 'default_uom': uom.id, }]) product, = self.Product.create([{ 'template': template.id, 'displayed_on_eshop': True, 'uri': 'test-product', }]) with app.test_request_context('/'): rv = product.get_menu_item(max_depth=10) self.assertEqual(rv['title'], product.name)
def test_0100_product_images(self): """ Test for adding product images """ Product = POOL.get('product.product') StaticFolder = POOL.get("nereid.static.folder") StaticFile = POOL.get("nereid.static.file") Media = POOL.get('product.media') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() self.create_test_products() folder, = StaticFolder.create([{ 'name': 'Test' }]) file_buffer = buffer('test-content') file, = StaticFile.create([{ 'name': 'test.png', 'folder': folder.id, 'file_binary': file_buffer }]) product, = Product.search([], limit=1) Media.create([{ 'product': product.id, 'template': product.template.id, 'static_file': file.id, }]) app = self.get_app() with app.test_request_context('/'): home_template = render_template('home.jinja', product=product) self.assertTrue(file.name in home_template)
def _create_product_template( self, name, vlist, uri, uom=u'Unit', displayed_on_eshop=True ): """ Create a product template with products and return its ID :param name: Name of the product :param vlist: List of dictionaries of values to create :param uri: uri of product template :param uom: Note it is the name of UOM (not symbol or code) :param displayed_on_eshop: Boolean field to display product on shop or not """ ProductTemplate = POOL.get('product.template') Uom = POOL.get('product.uom') for values in vlist: values['name'] = name values['default_uom'], = Uom.search([('name', '=', uom)], limit=1) values['products'] = [ ('create', [{ 'uri': uri, 'displayed_on_eshop': displayed_on_eshop, }]) ] return ProductTemplate.create(vlist)
def _create_fiscal_year(self, date=None, company=None): """ Creates a fiscal year and requried sequences """ FiscalYear = POOL.get('account.fiscalyear') Sequence = POOL.get('ir.sequence') Company = POOL.get('company.company') if date is None: date = datetime.date.today() if company is None: company, = Company.search([], limit=1) fiscal_year, = FiscalYear.create([{ 'name': '%s' % date.year, 'start_date': date + relativedelta(month=1, day=1), 'end_date': date + relativedelta(month=12, day=31), 'company': company, 'post_move_sequence': Sequence.create([{ 'name': '%s' % date.year, 'code': 'account.move', 'company': company, }])[0], }]) FiscalYear.create_period([fiscal_year]) return fiscal_year
def test_0050_import_grouped_product(self): """ Test the import of a grouped product using magento data """ Category = POOL.get('product.category') Product = POOL.get('product.product') with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() category_data = load_json('categories', 22) product_data = load_json('products', 54) with txn.set_context({ 'current_channel': self.channel1.id, 'company': self.company.id, }): Category.create_using_magento_data(category_data) product = Product.find_or_create_using_magento_data( product_data ) self.assertEqual( product.category.magento_ids[0].magento_id, 22 ) self.assertEqual( product.channel_listings[0].magento_product_type, 'grouped' )
def test_0080_import_sale_order_with_bundle_product(self): """ Tests import of sale order with bundle product using magento data """ Sale = POOL.get('sale.sale') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): order_states_list = load_json('order-states', 'all') for code, name in order_states_list.iteritems(): self.channel1.create_order_state(code, name) category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '300000001') with patch( 'magento.Customer', mock_customer_api(), create=True): self.Party.find_or_create_using_magento_id( order_data['customer_id'] ) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch( 'magento.Product', mock_product_api(), create=True ): order = Sale.find_or_create_using_magento_data( order_data ) self.assertEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), 2) self.assertEqual( order.total_amount, Decimal(order_data['base_grand_total']) ) # There should be a BoM for the bundle product product = self.channel1.import_product('VGN-TXN27N-BW') self.assertEqual(len(product.boms), 1) self.assertEqual( len(product.boms[0].bom.inputs), 2 )
def setUp(self): super(BaseTestCheckout, self).setUp() trytond.tests.test_tryton.install_module('nereid_checkout') self.Journal = POOL.get('account.journal') self.Category = POOL.get('product.category') self.Account = POOL.get('account.account') self.templates.update({ 'checkout/signin.jinja': '{{form.errors|safe}}', 'checkout/signin-email-in-use.jinja': '{{email}} in use', 'checkout/shipping_address.jinja': '{{address_form.errors|safe}}', 'checkout/billing_address.jinja': '{{address_form.errors|safe}}', 'checkout/payment_method.jinja': '''[ {{payment_form.errors|safe}}, {{credit_card_form.errors|safe}}, ]''', 'emails/sale-confirmation-text.jinja': ' ', 'emails/sale-confirmation-html.jinja': ' ', 'checkout.jinja': '{{form.errors|safe}}', 'sale.jinja': ' ', 'sales.jinja': '''{{request.args.get('filter_by')}} {% for sale in sales %}#{{sale.id}}{% endfor %} ''' }) # Patch SMTP Lib self.smtplib_patcher = patch('smtplib.SMTP') self.PatchedSMTP = self.smtplib_patcher.start()
def _create_auth_net_gateway_for_site(self): """ A helper function that creates the authorize.net gateway and assigns it to the websites. """ PaymentGateway = POOL.get('payment_gateway.gateway') NereidWebsite = POOL.get('nereid.website') Journal = POOL.get('account.journal') cash_journal, = Journal.search([ ('name', '=', 'Cash') ]) gateway = PaymentGateway( name='Authorize.net', journal=cash_journal, provider='authorize_net', method='credit_card', authorize_net_login='******', authorize_net_transaction_key='32jF65cTxja88ZA2', test=True ) gateway.save() websites = NereidWebsite.search([]) NereidWebsite.write(websites, { 'accept_credit_card': True, 'save_payment_profile': True, 'credit_card_gateway': gateway.id, }) return gateway
def setUp(self): trytond.tests.test_tryton.install_module('product') self.uom = POOL.get('product.uom') self.uom_category = POOL.get('product.uom.category') self.template = POOL.get('product.template') self.product = POOL.get('product.product') self.category = POOL.get('product.category')
def _create_fiscal_year(self, date=None, company=None): """ Creates a fiscal year and requried sequences """ Sequence = POOL.get("ir.sequence") SequenceStrict = POOL.get("ir.sequence.strict") if date is None: date = datetime.date.today() if company is None: company, = self.Company.search([], limit=1) invoice_sequence, = SequenceStrict.create( [{"name": "%s" % date.year, "code": "account.invoice", "company": company}] ) fiscal_year, = self.FiscalYear.create( [ { "name": "%s" % date.year, "start_date": date + relativedelta(month=1, day=1), "end_date": date + relativedelta(month=12, day=31), "company": company, "post_move_sequence": Sequence.create( [{"name": "%s" % date.year, "code": "account.move", "company": company}] )[0], "out_invoice_sequence": invoice_sequence, "in_invoice_sequence": invoice_sequence, "out_credit_note_sequence": invoice_sequence, "in_credit_note_sequence": invoice_sequence, } ] ) self.FiscalYear.create_period([fiscal_year]) return fiscal_year
def setUp(self): trytond.tests.test_tryton.install_module('elastic_search') self.IndexBacklog = POOL.get('elasticsearch.index_backlog') self.DocumentType = POOL.get('elasticsearch.document.type') self.User = POOL.get('res.user') self.Model = POOL.get('ir.model') self.Trigger = POOL.get('ir.trigger')
def test_0020_render_unicode(self): ''' Render the report without PDF conversion but having unicode template ''' UserReport = POOL.get('res.user', type='report') IRReport = POOL.get('ir.action.report') with Transaction().start(DB_NAME, USER, context=CONTEXT): self.setup_defaults() with Transaction().set_context(company=self.company.id): report_html, = IRReport.create([{ 'name': 'HTML Report', 'model': 'res.user', 'report_name': 'res.user', 'report_content': buffer( "<h1>Héllø, {{data['name']}}!</h1>" ), 'extension': 'html', }]) val = UserReport.execute([USER], {'name': u'Cédric'}) self.assertEqual(val[0], u'html') self.assertEqual( str(val[1]), '<h1>Héllø, Cédric!</h1>' )
def _create_fiscal_year(self, date=None, company=None): """ Creates a fiscal year and requried sequences """ Sequence = POOL.get('ir.sequence') SequenceStrict = POOL.get('ir.sequence.strict') if date is None: date = datetime.date.today() if company is None: company, = self.Company.search([], limit=1) invoice_sequence, = SequenceStrict.create([{ 'name': '%s' % date.year, 'code': 'account.invoice', 'company': company, }]) fiscal_year, = self.FiscalYear.create([{ 'name': '%s' % date.year, 'start_date': date + relativedelta(month=1, day=1), 'end_date': date + relativedelta(month=12, day=31), 'company': company, 'post_move_sequence': Sequence.create([{ 'name': '%s' % date.year, 'code': 'account.move', 'company': company, }])[0], 'out_invoice_sequence': invoice_sequence, 'in_invoice_sequence': invoice_sequence, 'out_credit_note_sequence': invoice_sequence, 'in_credit_note_sequence': invoice_sequence, }]) self.FiscalYear.create_period([fiscal_year]) return fiscal_year
def test_0050_import_grouped_product(self): """ Test the import of a grouped product using magento data """ Category = POOL.get('product.category') ProductTemplate = POOL.get('product.template') with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() category_data = load_json('categories', 22) product_data = load_json('products', 54) with txn.set_context({ 'magento_instance': self.instance1, 'magento_website': self.website1, 'company': self.company, }): Category.create_using_magento_data(category_data) template = ProductTemplate.find_or_create_using_magento_data( product_data ) self.assertEqual( template.category.magento_ids[0].magento_id, 22 ) self.assertEqual( template.magento_product_type, 'grouped' )
def _create_cheque_payment_method(self): """ A helper function that creates the cheque gateway and assigns it to the websites. """ PaymentGateway = POOL.get('payment_gateway.gateway') NereidWebsite = POOL.get('nereid.website') PaymentMethod = POOL.get('nereid.website.payment_method') Journal = POOL.get('account.journal') cash_journal, = Journal.search([ ('name', '=', 'Cash') ]) gateway = PaymentGateway( name='Offline Payment Methods', journal=cash_journal, provider='self', method='manual', ) gateway.save() website, = NereidWebsite.search([]) payment_method = PaymentMethod( name='Cheque', gateway=gateway, website=website ) payment_method.save() return payment_method
def test_0100_template_trans_tag_with_expr(self): """ Test for {% trans user=user.username %}Hello {{ user }}!{% endtrans %} tag """ TranslationSet = POOL.get('ir.translation.set', type='wizard') IRTranslation = POOL.get('ir.translation') with Transaction().start(DB_NAME, USER, CONTEXT): session_id, _, _ = TranslationSet.create() set_wizard = TranslationSet(session_id) # Set the nereid_template translations alone set_wizard.set_nereid_template() # XXX: See how {{ user }} changed to %(user)s translation, = IRTranslation.search([ ('type', '=', 'nereid_template'), ('module', '=', 'nereid_test'), ('src', '=', 'Hello %(name)s!') ]) self.assertEqual( translation.comments, 'Translation with an expression' ) self.assertEqual(translation.res_id, 26)
def test_0080_template_ngettext(self): """ Test for ngettext """ TranslationSet = POOL.get('ir.translation.set', type='wizard') IRTranslation = POOL.get('ir.translation') with Transaction().start(DB_NAME, USER, CONTEXT): session_id, _, _ = TranslationSet.create() set_wizard = TranslationSet(session_id) # Set the nereid_template translations alone set_wizard.set_nereid_template() translation, = IRTranslation.search([ ('type', '=', 'nereid_template'), ('module', '=', 'nereid_test'), ('src', '=', '%(num)d apple') ]) self.assertEqual(translation.res_id, 20) # Look for plural translation, = IRTranslation.search([ ('type', '=', 'nereid_template'), ('module', '=', 'nereid_test'), ('src', '=', '%(num)d apples') ]) self.assertEqual(translation.res_id, 20)
def test_0060_make_tree_crumbs(self): """ Test to get breadcrumbs on node template """ Node = POOL.get('product.tree_node') self.setup_defaults() app = self.get_app() parent_node, = Node.create([{ 'name': 'Node1', 'type_': 'catalog', 'slug': 'node1', 'parent': self.default_node, }]) child_node, = Node.create([{ 'name': 'Node2', 'type_': 'catalog', 'slug': 'node2', 'parent': parent_node, }]) with app.test_client() as c: rv = c.get('nodes/%d/node2' % child_node.id) self.assertEqual( rv.data[3:], "Home, root, Node1, Node2" )
def test0010_import_product(self): """ Test the import of simple product using eBay Data """ Product = POOL.get('product.product') with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() with txn.set_context({ 'current_channel': self.ebay_channel.id, 'company': self.company, }): products_before_import = Product.search([], count=True) product_data = load_json('products', '110162956809') product = Product.create_using_ebay_data(product_data) self.assertEqual(product.template.name, 'Iphone') products_after_import = Product.search([], count=True) self.assertTrue(products_after_import > products_before_import) self.assertEqual( product, self.ebay_channel.import_product('110162956809'))
def test_0020_kwargs(self): """ Test if kwargs work """ IRTranslation = POOL.get('ir.translation') s = _("Hi %(name)s", name="Sharoon") self.assertEqual(s, u"Hi Sharoon") # install translations self.set_translations() self.update_translations('fr_FR') # without setting a tranlsation looking for it gives en_US with Transaction().set_context(language="fr_FR"): self.assertEqual(s, u'Hi Sharoon') # write a translation for it translation, = IRTranslation.search([('module', '=', 'nereid'), ('src', '=', 'Hi %(name)s'), ('lang', '=', 'fr_FR')]) translation.value = 'Bonjour %(name)s' translation.save() with Transaction().set_context(language="fr_FR"): self.assertEqual(s, u'Bonjour Sharoon')
def test_0210_regd_alternate_payment(self): "Regd User - Alternate Payment Method" self.setup_defaults() app = self.get_app() Sale = POOL.get('sale.sale') # Define a new payment gateway cheque_method = self._create_cheque_payment_method() with app.test_client() as c: self._create_regd_user_order(c, 10) # Try to pay using credit card rv = c.post('/checkout/payment', data={'alternate_payment_method': cheque_method.id}) self.assertEqual(rv.status_code, 302) self.assertTrue('/order/' in rv.location) sale, = Sale.search([('state', '=', 'confirmed')]) # Process sale with payments self._process_sale_by_completing_payments([sale]) payment_transaction, = sale.gateway_transactions self.assertEqual(payment_transaction.amount, sale.total_amount) self.assertEqual(payment_transaction.state, 'completed')
def test_0220_test_dummy_profile_add(self): """ Test dummy gateway profile addition """ AddPaymentProfileWizard = POOL.get('party.party.payment_profile.add', type='wizard') self.setup_defaults() with Transaction().set_context(company=self.company.id, use_dummy=True): gateway, = self.PaymentGateway.create([{ 'name': 'Dummy Gateway', 'journal': self.cash_journal.id, 'provider': 'dummy', 'method': 'credit_card', }]) # create a profile profile_wiz = AddPaymentProfileWizard( AddPaymentProfileWizard.create()[0]) profile_wiz.card_info.party = self.party.id profile_wiz.card_info.address = self.party.addresses[0].id profile_wiz.card_info.provider = gateway.provider profile_wiz.card_info.gateway = gateway profile_wiz.card_info.owner = self.party.name profile_wiz.card_info.number = '4111111111111111' profile_wiz.card_info.expiry_month = '11' profile_wiz.card_info.expiry_year = '2018' profile_wiz.card_info.csc = '353' profile_wiz.transition_add()
def test_0010_create_amazon_account(self): """ Create amazon mws account """ Location = POOL.get('stock.location') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() warehouse, = Location.search([('type', '=', 'warehouse')], limit=1) account = self.MWSAccount.create([{ 'merchant_id': '1234', 'marketplace_id': '3456', 'access_key': 'AWS1', 'secret_key': 'S013', 'warehouse': warehouse.id, 'company': self.company.id, 'default_account_revenue': self.get_account_by_kind('revenue'), 'default_account_expense': self.get_account_by_kind('expense'), }]) self.assert_(account)
def test_0010_test_add_payment_profile(self): """ Test adding payment profile to a Party """ self.setup_defaults() ProfileWizard = POOL.get('party.party.payment_profile.add', type="wizard") profile_wizard = ProfileWizard(ProfileWizard.create()[0]) profile_wizard.card_info.owner = self.party2.name profile_wizard.card_info.number = self.card_data1.number profile_wizard.card_info.expiry_month = self.card_data1.expiry_month profile_wizard.card_info.expiry_year = self.card_data1.expiry_year profile_wizard.card_info.csc = self.card_data1.csc profile_wizard.card_info.gateway = self.auth_net_gateway profile_wizard.card_info.provider = self.auth_net_gateway.provider profile_wizard.card_info.address = self.party2.addresses[0] profile_wizard.card_info.party = self.party2 with Transaction().set_context(return_profile=True): profile = profile_wizard.transition_add() self.assertEqual(profile.party.id, self.party2.id) self.assertEqual(profile.gateway, self.auth_net_gateway) self.assertEqual(profile.last_4_digits, self.card_data1.number[-4:]) self.assertEqual(profile.expiry_month, self.card_data1.expiry_month) self.assertEqual(profile.expiry_year, self.card_data1.expiry_year) self.assertIsNotNone(profile.authorize_profile_id)
def test_0090_check_channel_exception(self): """ Check if channel exception is being created """ ChannelException = POOL.get('channel.exception') with Transaction().start(DB_NAME, USER, context=CONTEXT): self.setup_defaults() sale = self.create_sale(1, self.channel1) self.assertFalse(sale.has_channel_exception) channel_exception, = ChannelException.create([{ 'origin': '%s,%s' % (sale.__name__, sale.id), 'log': 'Sale has exception', 'channel': sale.channel.id, }]) self.assert_(channel_exception) self.assertTrue(sale.has_channel_exception) # Mark exception as resolved channel_exception.is_resolved = True channel_exception.save() self.assertFalse(sale.has_channel_exception)
def setUp(self): """ Set up data used in the tests. """ self.Currency = POOL.get('currency.currency') self.Company = POOL.get('company.company') self.Party = POOL.get('party.party') self.User = POOL.get('res.user') self.Journal = POOL.get('account.journal') self.PaymentGateway = POOL.get('payment_gateway.gateway') self.PaymentTransaction = POOL.get('payment_gateway.transaction') self.AccountMove = POOL.get('account.move') self.PaymentProfile = POOL.get('party.payment_profile') self.UseCardView = POOL.get( 'payment_gateway.transaction.use_card.view')
def test_0330_registered_user_payment_using_payment_profile(self): """ =================================== Total Sale Amount | $100 Payment Authorize On: | 'manual' Payment Capture On: | 'sale_process' =================================== Total Payment Lines | 1 Payment 1 | $100 =================================== """ Sale = POOL.get('sale.sale') self.setup_defaults() app = self.get_app() auth_gateway = self._create_auth_net_gateway_for_site() with app.test_client() as c: self._create_regd_user_order(c, 10) sale, = Sale.search([], limit=1) self.assertEqual(sale.total_amount, Decimal('100')) self.assertEqual(sale.payment_total, Decimal('0')) self.assertEqual(sale.payment_collected, Decimal('0')) self.assertEqual(sale.payment_captured, Decimal('0')) self.assertEqual(sale.payment_available, Decimal('0')) self.assertEqual(sale.payment_authorized, Decimal('0')) gateway = self._create_auth_net_gateway_for_site() payment_profile = self.create_payment_profile(sale.party, gateway) rv = c.post('/checkout/payment', data={'payment_profile': payment_profile.id}) self.assertEqual(rv.status_code, 302) self.assertEqual(sale.state, 'confirmed') self.assertEqual(len(sale.payments), 1) sale_payment, = sale.payments self.assertEqual(sale_payment.method, auth_gateway.method) self.assertEqual(sale.payment_total, Decimal('100')) self.assertEqual(sale.payment_available, Decimal('100')) self.assertEqual(sale.payment_collected, Decimal('0')) self.assertEqual(sale.payment_captured, Decimal('0')) self.assertEqual(sale.payment_authorized, Decimal('0')) with Transaction().set_context(company=self.company.id): self.Sale.process([sale]) self.Sale.process_all_pending_payments() self.assertEqual(sale.payment_total, Decimal('100')) self.assertEqual(sale.payment_available, Decimal('0')) self.assertEqual(sale.payment_collected, Decimal('100')) self.assertEqual(sale.payment_captured, Decimal('100')) self.assertEqual(sale.payment_authorized, Decimal('0'))
def test0060_ordered_search_same_timestamp(self): 'Test ordered search with same timestamp' History = POOL.get('test.history') order = [('value', 'ASC')] with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: history = History(value=1) history.save() first_stamp = history.create_date history.value = 4 history.save() second_stamp = history.write_date self.assertEqual(first_stamp, second_stamp) transaction.cursor.commit() results = [ (second_stamp, [history], [4]), (datetime.datetime.now(), [history], [4]), (datetime.datetime.max, [history], [4]), ] with Transaction().start(DB_NAME, USER, context=CONTEXT): for timestamp, instances, values in results: with Transaction().set_context(_datetime=timestamp, last_test=True): records = History.search([], order=order) self.assertEqual(records, instances) self.assertEqual([x.value for x in records], values)
def test0010_create_party(self): """ Tests if customers imported from magento is created as party in tryton """ MagentoParty = POOL.get('magento.website.party') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() Transaction().context.update({'magento_website': self.website1.id}) magento_data = load_json('customers', '1') customer_name = u' '.join( [magento_data['firstname'], magento_data['lastname']]) self.assertFalse(self.Party.search([('name', '=', customer_name)])) parties = MagentoParty.search([]) self.assertEqual(len(parties), 0) # Create party party = self.Party.find_or_create_using_magento_data(magento_data) self.assert_(party) self.assertTrue(self.Party.search([('name', '=', customer_name)])) self.assertTrue(len(party.contact_mechanisms), 1) self.assertTrue(party.contact_mechanisms[0].email) parties = MagentoParty.search([]) self.assertEqual(len(parties), 1)
def test0041restore_history_before(self): 'Test restore history before' History = POOL.get('test.history') with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: history = History(value=1) history.save() history_id = history.id transaction.cursor.commit() with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: history = History(history_id) history.value = 2 history.save() second = history.write_date transaction.cursor.commit() with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: history = History(history_id) history.value = 3 history.save() transaction.cursor.commit() with Transaction().start(DB_NAME, USER, context=CONTEXT): History.restore_history_before([history_id], second) history = History(history_id) self.assertEqual(history.value, 1)
def test_0030_check_prestashop_exception_order_total(self): """ Check if exception is created when order total does not match """ ChannelException = POOL.get('channel.exception') with Transaction().start(DB_NAME, USER, context=CONTEXT): # Call method to setup defaults self.setup_defaults() with Transaction().set_context( self.User.get_preferences(context_only=True), current_channel=self.channel.id, ps_test=True, ): self.setup_channels() order_data = get_objectified_xml('orders', 1) order_data.total_paid_tax_excl = 100 self.assertFalse(ChannelException.search([])) sale = self.Sale.find_or_create_using_ps_data(order_data) self.assertNotEqual(sale.total_amount, order_data.total_paid_tax_excl) self.assertTrue(sale.has_channel_exception) self.assertTrue(ChannelException.search([])) self.assertNotEqual(sale.state, 'done')
def test_0115_check_processing_of_sale(self): """ Check if channel exception is being created """ ChannelException = POOL.get('channel.exception') self.setup_defaults() sale = self.create_sale(1, self.channel1) self.assertFalse(sale.has_channel_exception) channel_exception, = ChannelException.create([{ 'origin': '%s,%s' % (sale.__name__, sale.id), 'log': 'Sale has exception', 'channel': sale.channel.id, }]) self.assert_(channel_exception) self.assertTrue(sale.has_channel_exception) # sale should not be confirmed as long as channel exception # is not resolved and error should be raised for it with self.assertRaises(UserError): self.Sale.confirm([sale]) # Mark exception as resolved channel_exception.is_resolved = True channel_exception.save() self.assertFalse(sale.has_channel_exception) # Exception error should not be raised after it is resolved self.Sale.confirm([sale])
def test0045restore_history_same_timestamp(self): 'Test restore history with same timestamp' History = POOL.get('test.history') with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: history = History(value=1) history.save() history_id = history.id first = history.create_date history.value = 2 history.save() second = history.create_date self.assertEqual(first, second) transaction.cursor.commit() with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: history = History(history_id) history.value = 3 history.save() transaction.cursor.commit() with Transaction().start(DB_NAME, USER, context=CONTEXT): History.restore_history([history_id], first) history = History(history_id) self.assertEqual(history.value, 2)
def test0020_create_product_duplicate(self): """ Tests if items imported from ebay is duplicated as product in tryton """ Product = POOL.get('product.product') with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() with txn.set_context({ 'current_channel': self.ebay_channel.id, 'company': self.company, }): ebay_data = load_json('products', '110162956809') # Create product product = Product.create_using_ebay_data(ebay_data) self.assert_(product) # Create again and it should fail self.assertRaises( UserError, Product.create_using_ebay_data, ebay_data, )
def test_collection_get_pagination(self): """ GET with a domain """ # Fetch result from tryton api first to compare with rest api with Transaction().start(DB_NAME, 0, readonly=True): IrModel = POOL.get('ir.model') count = IrModel.search_count([]) with app.test_client() as c: total_count = 0 for page in xrange(1, 100): # Try to Iterate over a 100 pages result = c.get('/%s/model/ir.model?page=%d' % (DB_NAME, page), headers={'Authorization': get_auth_header()}) page_count = len(json.loads(result.data)['items']) total_count += page_count if not page_count: break # ensure that the total count matches self.assertEqual(total_count, count) # Ensure that the empty page is above the range self.assertEqual(page - 1, math.ceil(count / 10))
def test_0010_simple_txn(self): """ Test if the translations work in a simple env """ IRTranslation = POOL.get('ir.translation') s = _("en_US") self.assertEqual(s, u'en_US') # install translations self.set_translations() self.update_translations('fr_FR') # without setting a tranlsation looking for it gives en_US with Transaction().set_context(language="fr_FR"): self.assertEqual(s, u'en_US') # write a translation for it translation, = IRTranslation.search([('module', '=', 'nereid'), ('src', '=', 'en_US'), ('lang', '=', 'fr_FR')]) translation.value = 'fr_FR' translation.save() with Transaction().set_context(language="fr_FR"): self.assertEqual(s, u'fr_FR')
def test_0010_send_mails(self, mock_smtp): """ Tests send_mails functionality. """ EmailQueue = POOL.get('email.queue') with Transaction().start(DB_NAME, USER, CONTEXT) as transaction: # Put some emails in queue f = Faker() for item in xrange(10): EmailQueue.queue_mail(f.email(), f.email(), f.text()) transaction.commit() self.assertEqual(EmailQueue.search([], count=True), 10) self.assertEqual( EmailQueue.search([('state', '=', 'outbox')], count=True), 10) with Transaction().start(DB_NAME, USER, CONTEXT) as transaction: # Run cron method to send mails EmailQueue.send_all() with Transaction().start(DB_NAME, USER, CONTEXT) as transaction: self.assertEqual( EmailQueue.search([('state', '=', 'sent')], count=True), 10)
def test_0090_tier_prices(self): """Checks the function field on product price tiers """ PriceList = POOL.get('product.price_list') ProductPriceTier = POOL.get('product.price_tier') Product = POOL.get('product.product') Category = POOL.get('product.category') User = POOL.get('res.user') with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() context = User.get_preferences(context_only=True) context.update({ 'current_channel': self.channel1.id, 'company': self.company.id, }) with txn.set_context(context): category_data = load_json('categories', '17') Category.create_using_magento_data(category_data) product_data = load_json('products', '135') product = Product.find_or_create_using_magento_data( product_data ) price_list, = PriceList.create([{ 'name': 'Test Pricelist', 'lines': [('create', [{ 'quantity': 10, 'formula': 'unit_price*0.9' }])] }]) self.channel1.price_list = price_list self.channel1.save() self.assertEqual(len(product.channel_listings), 1) listing = product.channel_listings[0] tier, = ProductPriceTier.create([{ 'product_listing': listing.id, 'quantity': 10, }]) self.assertEqual( listing.product.list_price * Decimal('0.9'), tier.price )
def test_0010_import_sale_order(self): """ Tests import of sale order using ebay data with ebay state as new """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Product = POOL.get('product.product') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.ebay_channel.id, 'company': self.company }): orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '283054010')['OrderArray']['Order'][0] Party.create_using_ebay_data( load_json('users', 'testuser_ritu123')) Product.create_using_ebay_data( load_json('products', '110162956809')) Product.create_using_ebay_data( load_json('products', '110162957156')) order1 = self.ebay_channel.import_order(order_data) self.assertEqual(order1.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order1.lines), 3) order2 = self.ebay_channel.import_order(order_data) orders = Sale.search([]) self.assertEqual(len(orders), 1) self.assertEqual(order1, order2)
def test_0110_export_catalog(self): """ Check the export of product catalog to magento. This method does not check the API calls. """ ProductTemplate = POOL.get('product.template') Category = POOL.get('product.category') Uom = POOL.get('product.uom') with Transaction().start(DB_NAME, USER, CONTEXT) as txn: self.setup_defaults() with txn.set_context({ 'magento_instance': self.instance1.id, 'magento_website': self.website1.id, 'magento_attribute_set': 1, 'company': self.company.id, }): category_data = load_json('categories', '17') category = Category.create_using_magento_data(category_data) uom, = Uom.search([('name', '=', 'Unit')], limit=1) product, = ProductTemplate.create([{ 'name': 'Test product', 'list_price': Decimal('100'), 'cost_price': Decimal('1'), 'account_expense': self.get_account_by_kind('expense'), 'account_revenue': self.get_account_by_kind('revenue'), 'default_uom': uom.id, 'sale_uom': uom.id, 'products': [('create', [{ 'code': 'code', 'description': 'This is a product description', }])] }]) with patch('magento.Product', mock_product_api(), create=True): product.export_to_magento(category)
def test_0030_import_sale_order_with_products_with_new(self): """ Tests import of sale order using magento data with magento state as new """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'magento_instance': self.instance1.id, 'magento_store_view': self.store_view, 'magento_website': self.website1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001') with patch('magento.Customer', mock_customer_api(), create=True): Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data) self.assertEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), len(order_data['items']) + 1)
def test_0020_test_paying_invoice_with_new_credit_card(self): """ Create and pay an invoice using payment transaction """ Date = POOL.get('ir.date') self.setup_defaults() invoice = self.create_and_post_invoice(self.party) self.assertTrue(invoice) self.assertEqual(invoice.state, 'posted') self.assertTrue(invoice.amount_to_pay) # Pay invoice using cash transaction Wizard = POOL.get( 'account.invoice.pay_using_transaction', type='wizard' ) with Transaction().set_context(active_id=invoice.id): pay_wizard = Wizard(Wizard.create()[0]) defaults = pay_wizard.default_start() pay_wizard.start.invoice = defaults['invoice'] pay_wizard.start.party = defaults['party'] pay_wizard.start.company = defaults['company'] pay_wizard.start.credit_account = defaults['credit_account'] pay_wizard.start.owner = defaults['owner'] pay_wizard.start.currency_digits = defaults['currency_digits'] pay_wizard.start.amount = defaults['amount'] pay_wizard.start.user = defaults['user'] pay_wizard.start.gateway = self.dummy_gateway.id pay_wizard.start.payment_profile = None pay_wizard.start.reference = 'Test paying with cash' pay_wizard.start.method = self.dummy_gateway.method pay_wizard.start.use_existing_card = False pay_wizard.start.number = '4111111111111111' pay_wizard.start.expiry_month = '05' pay_wizard.start.expiry_year = '%s' % (Date.today().year + 3) pay_wizard.start.csc = '435' pay_wizard.start.provider = self.dummy_gateway.provider pay_wizard.start.transaction_type = defaults['transaction_type'] with Transaction().set_context(company=self.company.id): pay_wizard.transition_pay() self.assertEqual(invoice.state, 'paid') self.assertFalse(invoice.amount_to_pay)
def test_0032_import_sale_order_without_firstname_and_lastname(self): """ Tests import of sale order using magento data without customer firstname and lastname """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000002') with patch('magento.Customer', mock_customer_api(), create=True): Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context(company=self.company): # Create sale order using magento data with patch('magento.Product', mock_product_api(), create=True): order = Sale.find_or_create_using_magento_data( order_data) self.assertEqual(order.state, 'confirmed') self.assertFalse(order.has_channel_exception) orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), len(order_data['items']) + 1)
def test_0040_find_or_create_order_using_increment_id(self): """ Tests finding and creating order using increment id """ Sale = POOL.get('sale.sale') Party = POOL.get('party.party') Category = POOL.get('product.category') with Transaction().start(DB_NAME, USER, CONTEXT): self.setup_defaults() with Transaction().set_context({ 'current_channel': self.channel1.id, }): category_tree = load_json('categories', 'category_tree') Category.create_tree_using_magento_data(category_tree) orders = Sale.search([]) self.assertEqual(len(orders), 0) order_data = load_json('orders', '100000001') with patch('magento.Customer', mock_customer_api(), create=True): Party.find_or_create_using_magento_id( order_data['customer_id']) with Transaction().set_context(company=self.company): # Create sale order using magento increment_id with patch('magento.Order', mock_order_api(), create=True): with patch('magento.Product', mock_product_api(), create=True): order = \ Sale.find_or_create_using_magento_increment_id( order_data['increment_id'] ) self.assertEqual(order.state, 'confirmed') orders = Sale.search([]) self.assertEqual(len(orders), 1) # Item lines + shipping line should be equal to lines on tryton self.assertEqual(len(order.lines), len(order_data['items']) + 1)
def test_0060_test_duplicate_payment_profile(self): """ Test that workflow is not effected if duplicate payment profile is there on authorize.net """ self.setup_defaults() expiry_year = str(date.today().year + 1) customer = authorize.Customer.create() authorize.CreditCard.create( customer.customer_id, { 'credit_card': { 'card_number': '4111111111111111', 'card_code': '523', 'expiration_date': '05/%s' % expiry_year, }, 'billing': self.party2.addresses[0].get_authorize_address('Test User'), }) # Create a payment profile with some random payment id payment_profile = self.PaymentProfile( party=self.party2, address=self.party2.addresses[0].id, gateway=self.auth_net_gateway.id, last_4_digits='1111', expiry_month='05', expiry_year=expiry_year, provider_reference='67382920', authorize_profile_id=customer.customer_id, ) payment_profile.save() # Create payment profile with same details as above ProfileWizard = POOL.get('party.party.payment_profile.add', type="wizard") profile_wizard = ProfileWizard(ProfileWizard.create()[0]) profile_wizard.card_info.owner = 'Test User' profile_wizard.card_info.number = '4111111111111111' profile_wizard.card_info.expiry_month = '05' profile_wizard.card_info.expiry_year = expiry_year profile_wizard.card_info.csc = '523' profile_wizard.card_info.gateway = self.auth_net_gateway profile_wizard.card_info.provider = self.auth_net_gateway.provider profile_wizard.card_info.address = self.party2.addresses[0] profile_wizard.card_info.party = self.party2 with Transaction().set_context(return_profile=True): profile = profile_wizard.transition_add() self.assertEqual(profile.party.id, self.party2.id) self.assertEqual(profile.gateway, self.auth_net_gateway) self.assertEqual(profile.last_4_digits, '1111') self.assertEqual(profile.expiry_month, '05') self.assertEqual(profile.expiry_year, expiry_year) self.assertIsNotNone(profile.authorize_profile_id) self.assertEqual(profile.authorize_profile_id, payment_profile.authorize_profile_id)
def test_0070_guest_use_delivery_as_billing(self): "Guest user uses shipping address for billing" self.setup_defaults() app = self.get_app() Sale = POOL.get('sale.sale') country = self.Country(self.available_countries[0]) subdivision = country.subdivisions[0] with app.test_client() as c: c.post('/cart/add', data={ 'product': self.product1.id, 'quantity': 5 }) # Sign-in rv = c.post('/checkout/sign-in', data={ 'email': '*****@*****.**', 'checkout_mode': 'guest', }) # Shipping address page gets rendered rv = c.post('/checkout/shipping-address', data={ 'name': 'Sharoon Thomas', 'street': 'Biscayne Boulevard', 'streetbis': 'Apt. 1906, Biscayne Park', 'zip': 'FL33137', 'city': 'Miami', 'country': country.id, 'subdivision': subdivision.id, }) self.assertEqual(rv.status_code, 302) # Post to delivery-address with same flag rv = c.post('/checkout/billing-address', data={'use_shipment_address': 'True'}) self.assertEqual(rv.status_code, 302) self.assertTrue(rv.location.endswith('/checkout/payment')) # Assert that just one address was created party, = self.Party.search([ ('contact_mechanisms.value', '=', '*****@*****.**'), ('contact_mechanisms.type', '=', 'email') ]) self.assertTrue(party) self.assertEqual(len(party.addresses), 1) address, = party.addresses self.assertEqual(address.street, 'Biscayne Boulevard') sales = Sale.search([ ('shipment_address', '=', address.id), ('invoice_address', '=', address.id), ]) self.assertEqual(len(sales), 1)
def _get_account_by_kind(self, kind, company=None, silent=True): """Returns an account with given spec :param kind: receivable/payable/expense/revenue :param silent: dont raise error if account is not found """ Account = POOL.get('account.account') Company = POOL.get('company.company') if company is None: company, = Company.search([], limit=1) accounts = Account.search([('kind', '=', kind), ('company', '=', company)], limit=1) if not accounts and not silent: raise Exception("Account not found") return accounts[0] if accounts else False