def _synchronize_cron(cr, registry): env = Environment(cr, SUPERUSER_ID, {'active_test': False}) cron = env.ref('crm_iap_lead_enrich.ir_cron_lead_enrichment') if cron: config = env['ir.config_parameter'].get_param( 'crm.iap.lead.enrich.setting', 'manual') cron.active = config != 'manual'
def view(self, db, token, action, id, view='calendar'): registry = registry_get(db) with registry.cursor() as cr: # Since we are in auth=none, create an env with SUPERUSER_ID env = Environment(cr, SUPERUSER_ID, {}) attendee = env['calendar.attendee'].search([('access_token', '=', token), ('event_id', '=', int(id))]) if not attendee: return request.not_found() timezone = attendee.partner_id.tz lang = attendee.partner_id.lang or 'en_US' event = env['calendar.event'].with_context(tz=timezone, lang=lang).browse(int(id)) # If user is internal and logged, redirect to form view of event # otherwise, display the simplifyed web page with event informations if request.session.uid and request.env['res.users'].browse(request.session.uid).user_has_groups('base.group_user'): return werkzeug.utils.redirect('/web?db=%s#id=%s&view_type=form&model=calendar.event' % (db, id)) # NOTE : we don't use request.render() since: # - we need a template rendering which is not lazy, to render before cursor closing # - we need to display the template in the language of the user (not possible with # request.render()) response_content = env['ir.ui.view'].with_context(lang=lang).render_template( 'calendar.invitation_page_anonymous', { 'event': event, 'attendee': attendee, }) return request.make_response(response_content, headers=[('Content-Type', 'text/html')])
def post_init_hook(cr, registry): env = Environment(cr, SUPERUSER_ID, {}) res_ids = env['ir.model.data'].search([ ('model', '=', 'ir.ui.menu'), ('module', '=', 'sale'), ]).mapped('res_id') env['ir.ui.menu'].browse(res_ids).update({'active': True})
def uninstall_hook(cr, registry): env = Environment(cr, SUPERUSER_ID, {}) res_ids = env['ir.model.data'].search([ ('model', '=', 'ir.ui.menu'), ('module', '=', 'account') ]).mapped('res_id') env['ir.ui.menu'].browse(res_ids).update({'active': False})
def declined(self, db, token, action, id): registry = registry_get(db) with registry.cursor() as cr: env = Environment(cr, SUPERUSER_ID, {}) attendee = env['calendar.attendee'].search([('access_token', '=', token), ('state', '!=', 'declined')]) if attendee: attendee.do_decline() return self.view(db, token, action, id, view='form')
def post_init_check(cr, registery): env = Environment(cr, SUPERUSER_ID, {}) move_obj = env['stock.move'] move_ids = move_obj.search([]) move_ids.set_move_type() done_moves = move_obj.search([('state', '=', 'done')], order='date') done_moves.check_move_bal_qty() return True
def poll(self, channels, last, options=None): if request.env.user.has_group('base.group_user'): ip_address = request.httprequest.remote_addr users_log = request.env['res.users.log'].search_count([ ('create_uid', '=', request.env.user.id), ('ip', '=', ip_address), ('create_date', '>=', Datetime.to_string(Datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)))]) if not users_log: with registry(request.env.cr.dbname).cursor() as cr: env = Environment(cr, request.env.user.id, {}) env['res.users.log'].create({'ip': ip_address}) return super(BusController, self).poll(channels, last, options=options)
def test_tour(self): self.phantom_js("/", "flectra.__DEBUG__.services['web_tour.tour'].run('website_crm_tour')", "flectra.__DEBUG__.services['web_tour.tour'].tours.website_crm_tour.ready") # need environment using the test cursor as it's not committed cr = self.registry.cursor() assert cr is self.registry.test_cr env = Environment(cr, self.uid, {}) record = env['crm.lead'].search([('description', '=', '### TOUR DATA ###')]) assert len(record) == 1 assert record.contact_name == 'John Smith' assert record.email_from == '*****@*****.**' assert record.partner_name == 'Flectra S.A.'
def test_tour(self): self.phantom_js("/", "flectra.__DEBUG__.services['web_tour.tour'].run('website_hr_recruitment_tour')", "flectra.__DEBUG__.services['web_tour.tour'].tours.website_hr_recruitment_tour.ready") # get test cursor to read from same transaction browser is writing to cr = self.registry.cursor() assert cr == self.registry.test_cr env = Environment(cr, self.uid, {}) record = env['hr.applicant'].search([('description', '=', '### HR RECRUITMENT TEST DATA ###')]) assert len(record) == 1 assert record.partner_name == "John Smith" assert record.email_from == "*****@*****.**" assert record.partner_phone == '118.218'
def setUp(self): super(TestConfirmUnsubscribe, self).setUp() cr = self.registry.cursor() # apparently HttpCase does not properly update self.env? self.env2 = env = Environment(cr, self.uid, {}) self.partner = env['res.partner'].create({ 'name': 'Bob', 'email': '*****@*****.**' }) self.mailing_list = env['mail.channel'].create({ 'name': 'Test Mailing List', 'public': 'public', }) self.token = self.mailing_list._generate_action_token( self.partner.id, action='unsubscribe')
def _auth_method_calendar(cls): token = request.params['token'] dbname = request.params['db'] registry = flectra.registry(dbname) error_message = False with registry.cursor() as cr: env = Environment(cr, SUPERUSER_ID, {}) attendee = env['calendar.attendee'].sudo().search( [('access_token', '=', token)], limit=1) if not attendee: error_message = """Invalid Invitation Token.""" elif request.session.uid and request.session.login != 'anonymous': # if valid session but user is not match user = env['res.users'].sudo().browse(request.session.uid) if attendee.partner_id != user.partner_id: error_message = """Invitation cannot be forwarded via email. This event/meeting belongs to %s and you are logged in as %s. Please ask organizer to add you.""" % ( attendee.email, user.email) if error_message: raise BadRequest(error_message) return True
def uninstall_hook(cr, registry): env = Environment(cr, SUPERUSER_ID, {}) recs = env['bi.sql.view'].search([]) for rec in recs: rec.button_set_draft()
def test_01_pos_basic_order(self): cr = self.registry.cursor() assert cr == self.registry.test_cr env = Environment(cr, self.uid, {}) # By default parent_store computation is deferred until end of # tests. Pricelist items however are sorted based on these # fields, so they need to be computed. env['product.category']._parent_store_compute() journal_obj = env['account.journal'] account_obj = env['account.account'] main_company = env.ref('base.main_company') main_pos_config = env.ref('point_of_sale.pos_config_main') account_receivable = account_obj.create({ 'code': 'X1012', 'name': 'Account Receivable - Test', 'user_type_id': env.ref('account.data_account_type_receivable').id, 'reconcile': True }) field = self.env['ir.model.fields'].search( [('name', '=', 'property_account_receivable_id'), ('model', '=', 'res.partner'), ('relation', '=', 'account.account')], limit=1) env['ir.property'].create({ 'name': 'property_account_receivable_id', 'company_id': main_company.id, 'fields_id': field.id, 'value': 'account.account,' + str(account_receivable.id) }) # test an extra price on an attribute pear = env.ref('point_of_sale.poire_conference') attribute_value = env['product.attribute.value'].create({ 'name': 'add 2', 'product_ids': [(6, 0, [pear.id])], 'attribute_id': env['product.attribute'].create({ 'name': 'add 2', }).id, }) env['product.attribute.price'].create({ 'product_tmpl_id': pear.product_tmpl_id.id, 'price_extra': 2, 'value_id': attribute_value.id, }) fixed_pricelist = env['product.pricelist'].create({ 'name': 'Fixed', 'item_ids': [ (0, 0, { 'compute_price': 'fixed', 'fixed_price': 1, }), (0, 0, { 'compute_price': 'fixed', 'fixed_price': 2, 'applied_on': '0_product_variant', 'product_id': env.ref('point_of_sale.boni_orange').id, }), ( 0, 0, { 'compute_price': 'fixed', 'fixed_price': 13.95, # test for issues like in 7f260ab517ebde634fc274e928eb062463f0d88f 'applied_on': '0_product_variant', 'product_id': env.ref('point_of_sale.papillon_orange').id, }) ], }) env['product.pricelist'].create({ 'name': 'Percentage', 'item_ids': [(0, 0, { 'compute_price': 'percentage', 'percent_price': 100, 'applied_on': '0_product_variant', 'product_id': env.ref('point_of_sale.boni_orange').id, }), (0, 0, { 'compute_price': 'percentage', 'percent_price': 99, 'applied_on': '0_product_variant', 'product_id': env.ref('point_of_sale.papillon_orange').id, }), (0, 0, { 'compute_price': 'percentage', 'percent_price': 0, 'applied_on': '0_product_variant', 'product_id': env.ref('point_of_sale.citron').id, })], }) env['product.pricelist'].create({ 'name': 'Formula', 'item_ids': [ (0, 0, { 'compute_price': 'formula', 'price_discount': 6, 'price_surcharge': 5, 'applied_on': '0_product_variant', 'product_id': env.ref('point_of_sale.boni_orange').id, }), ( 0, 0, { # .99 prices 'compute_price': 'formula', 'price_surcharge': -0.01, 'price_round': 1, 'applied_on': '0_product_variant', 'product_id': env.ref('point_of_sale.papillon_orange').id, }), (0, 0, { 'compute_price': 'formula', 'price_min_margin': 10, 'price_max_margin': 100, 'applied_on': '0_product_variant', 'product_id': env.ref('point_of_sale.citron').id, }), (0, 0, { 'compute_price': 'formula', 'price_surcharge': 10, 'price_max_margin': 5, 'applied_on': '0_product_variant', 'product_id': env.ref('point_of_sale.limon').id, }), (0, 0, { 'compute_price': 'formula', 'price_discount': -100, 'price_min_margin': 5, 'price_max_margin': 20, 'applied_on': '0_product_variant', 'product_id': env.ref( 'point_of_sale.pamplemousse_rouge_pamplemousse').id, }) ], }) env['product.pricelist'].create({ 'name': 'min_quantity ordering', 'item_ids': [(0, 0, { 'compute_price': 'fixed', 'fixed_price': 1, 'applied_on': '0_product_variant', 'min_quantity': 2, 'product_id': env.ref('point_of_sale.boni_orange').id, }), (0, 0, { 'compute_price': 'fixed', 'fixed_price': 2, 'applied_on': '0_product_variant', 'min_quantity': 1, 'product_id': env.ref('point_of_sale.boni_orange').id, }), (0, 0, { 'compute_price': 'fixed', 'fixed_price': 2, 'applied_on': '0_product_variant', 'min_quantity': 2, 'product_id': env.ref('point_of_sale.product_product_consumable').id, })], }) env['product.pricelist'].create({ 'name': 'Product template', 'item_ids': [(0, 0, { 'compute_price': 'fixed', 'fixed_price': 1, 'applied_on': '1_product', 'product_tmpl_id': env.ref('point_of_sale.boni_orange_product_template').id, }), (0, 0, { 'compute_price': 'fixed', 'fixed_price': 2, })], }) env['product.pricelist'].create({ # no category has precedence over category 'name': 'Category vs no category', 'item_ids': [ ( 0, 0, { 'compute_price': 'fixed', 'fixed_price': 1, 'applied_on': '2_product_category', 'categ_id': env.ref('product.product_category_3'). id, # All / Saleable / Services }), (0, 0, { 'compute_price': 'fixed', 'fixed_price': 2, }) ], }) p = env['product.pricelist'].create({ 'name': 'Category', 'item_ids': [ (0, 0, { 'compute_price': 'fixed', 'fixed_price': 2, 'applied_on': '2_product_category', 'categ_id': env.ref('product.product_category_all').id, }), ( 0, 0, { 'compute_price': 'fixed', 'fixed_price': 1, 'applied_on': '2_product_category', 'categ_id': env.ref('product.product_category_3'). id, # All / Saleable / Services }) ], }) today = date.today() one_week_ago = today - timedelta(weeks=1) two_weeks_ago = today - timedelta(weeks=2) one_week_from_now = today + timedelta(weeks=1) two_weeks_from_now = today + timedelta(weeks=2) env['product.pricelist'].create({ 'name': 'Dates', 'item_ids': [(0, 0, { 'compute_price': 'fixed', 'fixed_price': 1, 'date_start': two_weeks_ago.strftime(DEFAULT_SERVER_DATE_FORMAT), 'date_end': one_week_ago.strftime(DEFAULT_SERVER_DATE_FORMAT), }), (0, 0, { 'compute_price': 'fixed', 'fixed_price': 2, 'date_start': today.strftime(DEFAULT_SERVER_DATE_FORMAT), 'date_end': one_week_from_now.strftime(DEFAULT_SERVER_DATE_FORMAT), }), (0, 0, { 'compute_price': 'fixed', 'fixed_price': 3, 'date_start': one_week_from_now.strftime(DEFAULT_SERVER_DATE_FORMAT), 'date_end': two_weeks_from_now.strftime(DEFAULT_SERVER_DATE_FORMAT), })], }) cost_base_pricelist = env['product.pricelist'].create({ 'name': 'Cost base', 'item_ids': [(0, 0, { 'base': 'standard_price', 'compute_price': 'percentage', 'percent_price': 55, })], }) pricelist_base_pricelist = env['product.pricelist'].create({ 'name': 'Pricelist base', 'item_ids': [(0, 0, { 'base': 'pricelist', 'base_pricelist_id': cost_base_pricelist.id, 'compute_price': 'percentage', 'percent_price': 15, })], }) env['product.pricelist'].create({ 'name': 'Pricelist base 2', 'item_ids': [(0, 0, { 'base': 'pricelist', 'base_pricelist_id': pricelist_base_pricelist.id, 'compute_price': 'percentage', 'percent_price': 3, })], }) env['product.pricelist'].create({ 'name': 'Pricelist base rounding', 'item_ids': [(0, 0, { 'base': 'pricelist', 'base_pricelist_id': fixed_pricelist.id, 'compute_price': 'percentage', 'percent_price': 0.01, })], }) excluded_pricelist = env['product.pricelist'].create( {'name': 'Not loaded'}) env.ref('base.res_partner_18' ).property_product_pricelist = excluded_pricelist # set the company currency to USD, otherwise it will assume # euro's. this will cause issues as the sales journal is in # USD, because of this all products would have a different # price main_company.currency_id = env.ref('base.USD') test_sale_journal = journal_obj.create({ 'name': 'Sales Journal - Test', 'code': 'TSJ', 'type': 'sale', 'company_id': main_company.id }) all_pricelists = env['product.pricelist'].search([ ('id', '!=', excluded_pricelist.id) ]) all_pricelists.write(dict(currency_id=main_company.currency_id.id)) main_pos_config.write({ 'journal_id': test_sale_journal.id, 'invoice_journal_id': test_sale_journal.id, 'journal_ids': [(0, 0, { 'name': 'Cash Journal - Test', 'code': 'TSC', 'type': 'cash', 'company_id': main_company.id, 'journal_user': True })], 'available_pricelist_ids': [(4, pricelist.id) for pricelist in all_pricelists], }) # open a session, the /pos/web controller will redirect to it main_pos_config.open_session_cb() # needed because tests are run before the module is marked as # installed. In js web will only load qweb coming from modules # that are returned by the backend in module_boot. Without # this you end up with js, css but no qweb. env['ir.module.module'].search([('name', '=', 'point_of_sale')], limit=1).state = 'installed' cr.release() self.phantom_js( "/pos/web", "flectra.__DEBUG__.services['web_tour.tour'].run('pos_pricelist')", "flectra.__DEBUG__.services['web_tour.tour'].tours.pos_pricelist.ready", login="******") self.phantom_js( "/pos/web", "flectra.__DEBUG__.services['web_tour.tour'].run('pos_basic_order')", "flectra.__DEBUG__.services['web_tour.tour'].tours.pos_basic_order.ready", login="******") for order in env['pos.order'].search([]): self.assertEqual( order.state, 'paid', "Validated order has payment of " + str(order.amount_paid) + " and total of " + str(order.amount_total))
def _install_sale_payment(cr, registry): env = Environment(cr, SUPERUSER_ID, {}) env['ir.module.module'].search([ ('name', '=', 'sale_payment'), ('state', '=', 'uninstalled'), ]).button_install()
def post_init_hook(cr, pool): env = Environment(cr, SUPERUSER_ID, {}) create_warehouse_procurement_rules(env)