Ejemplo n.º 1
0
    def setUpClass(cls, chart_template_ref=None):
        super().setUpClass(chart_template_ref=chart_template_ref)

        cls.company_a = cls.company_data['company']
        cls.company_b = cls.company_data_2['company']

        cls.user_company_a = cls.internal_user
        cls.user_company_b = cls.env['res.users'].create({
            'name': f"{cls.company_b.name} User (TEST)",
            'login': '******',
            'password': '******',
            'company_id': cls.company_b.id,
            'company_ids': [Command.set(cls.company_b.ids)],
            'groups_id': [Command.link(cls.group_user.id)],
        })
        cls.user_multi_company = cls.env['res.users'].create({
            'name': "Multi Company User (TEST)",
            'login': '******',
            'password': '******',
            'company_id': cls.company_a.id,
            'company_ids': [Command.set([cls.company_a.id, cls.company_b.id])],
            'groups_id': [Command.link(cls.group_user.id)],
        })

        cls.acquirer_company_b = cls._prepare_acquirer(company=cls.company_b)
 def setUpClass(cls):
     super().setUpClass()
     cls.users = cls.env['test_read_group.user'].create([
         {
             'name': 'Mario'
         },
         {
             'name': 'Luigi'
         },
     ])
     cls.tasks = cls.env['test_read_group.task'].create([
         {   # both users
             'name': "Super Mario Bros.",
             'user_ids': [Command.set(cls.users.ids)],
         },
         {   # mario only
             'name': "Paper Mario",
             'user_ids': [Command.set(cls.users[0].ids)],
         },
         {   # luigi only
             'name': "Luigi's Mansion",
             'user_ids': [Command.set(cls.users[1].ids)],
         },
         {   # no user
             'name': 'Donkey Kong',
             'user_ids': [Command.set([])],
         },
     ])
Ejemplo n.º 3
0
    def setUpClass(cls):
        super().setUpClass()

        cls.company_a = cls.env.company
        cls.company_b = cls.env['res.company'].create(
            {'name': "Odoo Inc (TEST)"})

        cls.user_company_a = cls.internal_user
        cls.user_company_b = cls.env['res.users'].create({
            'name':
            f"{cls.company_b.name} User (TEST)",
            'login':
            '******',
            'password':
            '******',
            'company_id':
            cls.company_b.id,
            'company_ids': [Command.set(cls.company_b.ids)],
            'groups_id': [Command.link(cls.group_user.id)],
        })
        cls.user_multi_company = cls.env['res.users'].create({
            'name':
            "Multi Company User (TEST)",
            'login':
            '******',
            'password':
            '******',
            'company_id':
            cls.company_a.id,
            'company_ids': [Command.set([cls.company_a.id, cls.company_b.id])],
            'groups_id': [Command.link(cls.group_user.id)],
        })

        cls.acquirer_company_b = cls._prepare_acquirer(company=cls.company_b)
Ejemplo n.º 4
0
 def test_reference_is_computed_based_on_document_name(self):
     """ Test computation of reference prefixes based on the provided invoice. """
     invoice = self.env['account.move'].create({})
     reference = self.env['payment.transaction']._compute_reference(
         self.ogone.provider, invoice_ids=[Command.set([invoice.id])]
     )
     self.assertEqual(reference, 'MISC/2011/11/0001-20111102120021')
Ejemplo n.º 5
0
    def _create_transaction(self,
                            *args,
                            sale_order_id=None,
                            custom_create_values=None,
                            **kwargs):
        """ Override of payment to add the sale order id in the custom create values.

        :param int sale_order_id: The sale order for which a payment id made, as a `sale.order` id
        :param dict custom_create_values: Additional create values overwriting the default ones
        :return: The result of the parent method
        :rtype: recordset of `payment.transaction`
        """
        if sale_order_id:
            if custom_create_values is None:
                custom_create_values = {}
            # As this override is also called if the flow is initiated from sale or website_sale, we
            # need not to override whatever value these modules could have already set
            if 'sale_order_ids' not in custom_create_values:  # We are in the payment module's flow
                custom_create_values['sale_order_ids'] = [
                    Command.set([int(sale_order_id)])
                ]

        return super()._create_transaction(
            *args,
            sale_order_id=sale_order_id,
            custom_create_values=custom_create_values,
            **kwargs)
Ejemplo n.º 6
0
    def portal_order_transaction(self, order_id, access_token, **kwargs):
        """ Create a draft transaction and return its processing values.

        :param int order_id: The sales order to pay, as a `sale.order` id
        :param str access_token: The access token used to authenticate the request
        :param dict kwargs: Locally unused data passed to `_create_transaction`
        :return: The mandatory values for the processing of the transaction
        :rtype: dict
        :raise: ValidationError if the invoice id or the access token is invalid
        """
        # Check the order id and the access token
        try:
            self._document_check_access('sale.order', order_id, access_token)
        except MissingError as error:
            raise error
        except AccessError:
            raise ValidationError("The access token is invalid.")

        kwargs.update({
            'reference_prefix':
            None,  # Allow the reference to be computed based on the order
            'sale_order_id':
            order_id,  # Include the SO to allow Subscriptions tokenizing the tx
        })
        kwargs.pop('custom_create_values',
                   None)  # Don't allow passing arbitrary create values
        tx_sudo = self._create_transaction(
            custom_create_values={'sale_order_ids': [Command.set([order_id])]},
            **kwargs,
        )

        return tx_sudo._get_processing_values()
Ejemplo n.º 7
0
 def test_subtask_log_timesheet(self):
     """ Test parent task takes into account the timesheets of its sub-tasks.
         Test Case:
         ----------
         1) Create parent task
         2) Create child/subtask task
         3) Enter the 8 hour timesheet in the child task
         4) Check subtask Effective hours in parent task
     """
     self.task1.child_ids = [Command.set([self.task2.id])]
     self.env['account.analytic.line'].create({
         'name':
         'FirstTimeSheet',
         'project_id':
         self.project_customer.id,
         'task_id':
         self.task2.id,
         'unit_amount':
         8.0,
         'employee_id':
         self.empl_employee2.id,
     })
     self.assertEqual(
         self.task1.subtask_effective_hours, 8,
         'Hours Spent on Sub-tasks should be 8 hours in Parent Task')
     self.task1.child_ids = [Command.clear()]
Ejemplo n.º 8
0
    def invoice_transaction(self, invoice_id, access_token, **kwargs):
        """ Create a draft transaction and return its processing values.

        :param int invoice_id: The invoice to pay, as an `account.move` id
        :param str access_token: The access token used to authenticate the request
        :param dict kwargs: Locally unused data passed to `_create_transaction`
        :return: The mandatory values for the processing of the transaction
        :rtype: dict
        :raise: ValidationError if the invoice id or the access token is invalid
        """
        # Check the invoice id and the access token
        try:
            self._document_check_access('account.move', invoice_id,
                                        access_token)
        except MissingError as error:
            raise error
        except AccessError:
            raise ValidationError("The access token is invalid.")

        kwargs[
            'reference_prefix'] = None  # Allow the reference to be computed based on the invoice
        kwargs.pop('custom_create_values',
                   None)  # Don't allow passing arbitrary create values
        tx_sudo = self._create_transaction(
            custom_create_values={'invoice_ids': [Command.set([invoice_id])]},
            **kwargs,
        )

        return tx_sudo._get_processing_values()
Ejemplo n.º 9
0
    def test_log_timesheet_with_analytic_tags(self):
        """ Test whether the analytic tag of the project or task is set on the timesheet.

            Test Case:
            ----------
                1) Create analytic tags
                2) Add analytic tag in project
                3) Create timesheet
                4) Check the default analytic tag of the project and timesheet
                5) Add analytic tag in task
                6) Check the analytic tag of the timesheet and task
        """
        Timesheet = self.env['account.analytic.line']

        share_capital_tag, office_furn_tag = self.env[
            'account.analytic.tag'].create([
                {
                    'name': 'Share capital'
                },
                {
                    'name': 'Office Furniture'
                },
            ])

        self.project_customer.analytic_tag_ids = [
            Command.set((share_capital_tag + office_furn_tag).ids)
        ]

        timesheet = Timesheet.create({
            'project_id': self.project_customer.id,
            'name': 'my first timesheet',
            'unit_amount': 4,
        })
        self.assertEqual(timesheet.tag_ids,
                         self.project_customer.analytic_tag_ids)

        self.task2.analytic_tag_ids = [
            Command.set((share_capital_tag + office_furn_tag).ids)
        ]

        timesheet1 = Timesheet.create({
            'project_id': self.project_customer.id,
            'task_id': self.task2.id,
            'name': 'my first timesheet',
            'unit_amount': 4,
        })
        self.assertEqual(timesheet1.tag_ids, self.task2.analytic_tag_ids)
Ejemplo n.º 10
0
 def test_light_sales_orders_batch_creation_perf_without_taxes(self):
     self.products[0].taxes_id = [Command.set([])]
     with self.assertQueryCount(admin=59):
         self.env['sale.order'].create([{
             'partner_id': self.partners[0].id,
             'user_id': self.salesmans[0].id,
             "order_line": [
                 (0, 0, {"display_type": "line_note", "name": "NOTE"}),
                 (0, 0, {"display_type": "line_section", "name": "SECTION"}),
                 (0, 0, {'product_id': self.products[0].id})
             ]
         } for i in range(2)])
Ejemplo n.º 11
0
 def _onchange_authorize_payment_method_type(self):
     if self.authorize_payment_method_type == 'bank_account':
         self.display_as = _("Bank (powered by Authorize)")
         self.payment_icon_ids = [Command.clear()]
     else:
         self.display_as = _("Credit Card (powered by Authorize)")
         self.payment_icon_ids = [Command.set([self.env.ref(icon_xml_id).id for icon_xml_id in (
             'payment.payment_icon_cc_maestro',
             'payment.payment_icon_cc_mastercard',
             'payment.payment_icon_cc_discover',
             'payment.payment_icon_cc_diners_club_intl',
             'payment.payment_icon_cc_jcb',
             'payment.payment_icon_cc_visa',
         )])]
Ejemplo n.º 12
0
    def _create_transaction(
        self, payment_option_id, reference_prefix, amount, currency_id, partner_id, flow,
        tokenization_requested, landing_route, is_validation=False, invoice_id=None,
        custom_create_values=None, **kwargs
    ):
        """ Create a draft transaction based on the payment context and return it.

        :param int payment_option_id: The payment option handling the transaction, as a
                                      `payment.acquirer` id or a `payment.token` id
        :param str reference_prefix: The custom prefix to compute the full reference
        :param float|None amount: The amount to pay in the given currency.
                                  None if in a payment method validation operation
        :param int|None currency_id: The currency of the transaction, as a `res.currency` id.
                                     None if in a payment method validation operation
        :param int partner_id: The partner making the payment, as a `res.partner` id
        :param str flow: The online payment flow of the transaction: 'redirect', 'direct' or 'token'
        :param bool tokenization_requested: Whether the user requested that a token is created
        :param str landing_route: The route the user is redirected to after the transaction
        :param bool is_validation: Whether the operation is a validation
        :param int invoice_id: The account move for which a payment id made, as an `account.move` id
        :param dict custom_create_values: Additional create values overwriting the default ones
        :param dict kwargs: Locally unused data passed to `_is_tokenization_required` and
                            `_compute_reference`
        :return: The sudoed transaction that was created
        :rtype: recordset of `payment.transaction`
        :raise: UserError if the flow is invalid
        """
        # Prepare create values
        if flow in ['redirect', 'direct']:  # Direct payment or payment with redirection
            acquirer_sudo = request.env['payment.acquirer'].sudo().browse(payment_option_id)
            token_id = None
            tokenization_required_or_requested = acquirer_sudo._is_tokenization_required(
                provider=acquirer_sudo.provider, **kwargs
            ) or tokenization_requested
            tokenize = bool(
                # Don't tokenize if the user tried to force it through the browser's developer tools
                acquirer_sudo.allow_tokenization
                # Token is only created if required by the flow or requested by the user
                and tokenization_required_or_requested
            )
        elif flow == 'token':  # Payment by token
            token_sudo = request.env['payment.token'].sudo().browse(payment_option_id)

            # Prevent from paying with a token that doesn't belong to the current partner (either
            # the current user's partner if logged in, or the partner on behalf of whom the payment
            # is being made).
            partner_sudo = request.env['res.partner'].sudo().browse(partner_id)
            if partner_sudo.commercial_partner_id != token_sudo.partner_id.commercial_partner_id:
                raise AccessError(_("You do not have access to this payment token."))

            acquirer_sudo = token_sudo.acquirer_id
            token_id = payment_option_id
            tokenize = False
        else:
            raise UserError(
                _("The payment should either be direct, with redirection, or made by a token.")
            )

        if invoice_id:
            if custom_create_values is None:
                custom_create_values = {}
            custom_create_values['invoice_ids'] = [Command.set([int(invoice_id)])]

        reference = request.env['payment.transaction']._compute_reference(
            acquirer_sudo.provider,
            prefix=reference_prefix,
            **(custom_create_values or {}),
            **kwargs
        )
        if is_validation:  # Acquirers determine the amount and currency in validation operations
            amount = acquirer_sudo._get_validation_amount()
            currency_id = acquirer_sudo._get_validation_currency().id

        # Create the transaction
        tx_sudo = request.env['payment.transaction'].sudo().create({
            'acquirer_id': acquirer_sudo.id,
            'reference': reference,
            'amount': amount,
            'currency_id': currency_id,
            'partner_id': partner_id,
            'token_id': token_id,
            'operation': f'online_{flow}' if not is_validation else 'validation',
            'tokenize': tokenize,
            'landing_route': landing_route,
            **(custom_create_values or {}),
        })  # In sudo mode to allow writing on callback fields

        if flow == 'token':
            tx_sudo._send_payment_request()  # Payments by token process transactions immediately
        else:
            tx_sudo._log_sent_message()

        # Monitor the transaction to make it available in the portal
        PaymentPostProcessing.monitor_transactions(tx_sudo)

        return tx_sudo
    def test_purchase_requisition_stock_dropshipping(self):

        # create 'dropship - call for tender' product
        product = self.env['product.product'].create({'name': 'prsds-product'})
        dropshipping_route = self.env.ref(
            'stock_dropshipping.route_drop_shipping')
        product.write({'route_ids': [Command.set([dropshipping_route.id])]})
        product.write({'purchase_requisition': 'tenders'})

        # sell this product
        customer = self.env['res.partner'].create({'name': 'prsds-customer'})
        sale_order = self.env['sale.order'].create({
            'partner_id':
            customer.id,
            'partner_invoice_id':
            customer.id,
            'partner_shipping_id':
            customer.id,
            'order_line': [
                Command.create({
                    'name': product.name,
                    'product_id': product.id,
                    'product_uom_qty': 10.00,
                    'product_uom': product.uom_id.id,
                    'price_unit': 10,
                })
            ],
        })

        # confirm order
        sale_order.action_confirm()

        # call for tender must exists
        call_for_tender = self.env['purchase.requisition'].search([
            ('origin', '=', sale_order.name)
        ])
        self.assertTrue(call_for_tender)

        # confirm call for tender
        call_for_tender.action_in_progress()

        # create purchase order from call for tender
        vendor = self.env['res.partner'].create({'name': 'prsds-vendor'})
        f = Form(self.env['purchase.order'].with_context(
            default_requisition_id=call_for_tender))
        f.partner_id = vendor
        purchase_order = f.save()

        # check purchase order
        self.assertEqual(
            purchase_order.requisition_id.id, call_for_tender.id,
            'Purchase order should be linked with call for tender')
        self.assertEqual(purchase_order.dest_address_id.id, customer.id,
                         'Purchase order should be delivered at customer')
        self.assertEqual(len(purchase_order.order_line), 1,
                         'Purchase order should have one line')
        purchase_order_line = purchase_order.order_line
        self.assertEqual(purchase_order_line.sale_order_id.id, sale_order.id,
                         'Purchase order should be linked with sale order')
        self.assertEqual(
            purchase_order_line.sale_line_id.id, sale_order.order_line.id,
            'Purchase order line should be linked with sale order line')