Esempio n. 1
0
    def test_12_return_without_refund(self):
        """ Do the exact thing than in `test_11_return_with_refund` except we
        set on False the refund and checks the sale order delivered quantity
        isn't changed.
        """
        # Creates a sale order for 10 products.
        sale_order = self._get_new_sale_order()
        # Valids the sale order, then valids the delivery.
        sale_order.action_confirm()
        self.assertTrue(sale_order.picking_ids)
        self.assertEqual(sale_order.order_line.qty_delivered, 0)
        picking = sale_order.picking_ids
        picking.move_lines.write({'quantity_done': 10})
        picking.button_validate()

        # Checks the delivery amount (must be 10).
        self.assertEqual(sale_order.order_line.qty_delivered, 10)
        # Creates a return from the delivery picking.
        return_picking_form = Form(
            self.env['stock.return.picking'].with_context(
                active_ids=picking.ids,
                active_id=picking.id,
                active_model='stock.picking'))
        return_wizard = return_picking_form.save()
        # Checks the field `to_refund` is checked, then unchecks it.
        self.assertEqual(return_wizard.product_return_moves.to_refund, True)
        self.assertEqual(return_wizard.product_return_moves.quantity, 10)
        return_wizard.product_return_moves.to_refund = False
        # Valids the return picking.
        res = return_wizard.create_returns()
        return_picking = self.env['stock.picking'].browse(res['res_id'])
        return_picking.move_lines.write({'quantity_done': 10})
        return_picking.button_validate()
        # Checks the delivery amount (must still be 10).
        self.assertEqual(sale_order.order_line.qty_delivered, 10)
Esempio n. 2
0
    def test_survey_invite(self):
        Answer = self.env['survey.user_input']
        deadline = fields.Datetime.now() + relativedelta(months=1)

        self.survey.write({
            'access_mode': 'public',
            'users_login_required': False
        })
        action = self.survey.action_send_survey()
        invite_form = Form(self.env[action['res_model']].with_context(
            action['context']))

        # some lowlevel checks that action is correctly configured
        self.assertEqual(Answer.search([('survey_id', '=', self.survey.id)]),
                         self.env['survey.user_input'])
        self.assertEqual(invite_form.survey_id, self.survey)

        invite_form.partner_ids.add(self.customer)
        invite_form.deadline = fields.Datetime.to_string(deadline)

        invite = invite_form.save()
        invite.action_invite()

        answers = Answer.search([('survey_id', '=', self.survey.id)])
        self.assertEqual(len(answers), 1)
        self.assertEqual(set(answers.mapped('email')),
                         set([self.customer.email]))
        self.assertEqual(answers.mapped('partner_id'), self.customer)
        self.assertEqual(set(answers.mapped('deadline')), set([deadline]))
Esempio n. 3
0
    def test_survey_invite_authentication_nosignup(self):
        Answer = self.env['survey.user_input']

        self.survey.write({
            'access_mode': 'public',
            'users_login_required': True
        })
        action = self.survey.action_send_survey()
        invite_form = Form(self.env[action['res_model']].with_context(
            action['context']))

        with self.assertRaises(
                UserError
        ):  # do not allow to add customer (partner without user)
            invite_form.partner_ids.add(self.customer)
        invite_form.partner_ids.clear()
        invite_form.partner_ids.add(self.user_portal.partner_id)
        invite_form.partner_ids.add(self.user_emp.partner_id)
        with self.assertRaises(UserError):
            invite_form.emails = '[email protected], Raoulette Vignolette <*****@*****.**>'
        invite_form.emails = False

        invite = invite_form.save()
        invite.action_invite()

        answers = Answer.search([('survey_id', '=', self.survey.id)])
        self.assertEqual(len(answers), 2)
        self.assertEqual(set(answers.mapped('email')),
                         set([self.user_emp.email, self.user_portal.email]))
        self.assertEqual(
            answers.mapped('partner_id'),
            self.user_emp.partner_id | self.user_portal.partner_id)
Esempio n. 4
0
    def test_11_return_with_refund(self):
        """ Creates a sale order, valids it and its delivery, then creates a
        return. The return must refund by default and the sale order delivered
        quantity must be updated.
        """
        # Creates a sale order for 10 products.
        sale_order = self._get_new_sale_order()
        # Valids the sale order, then valids the delivery.
        sale_order.action_confirm()
        self.assertTrue(sale_order.picking_ids)
        self.assertEqual(sale_order.order_line.qty_delivered, 0)
        picking = sale_order.picking_ids
        picking.move_lines.write({'quantity_done': 10})
        picking.button_validate()

        # Checks the delivery amount (must be 10).
        self.assertEqual(sale_order.order_line.qty_delivered, 10)
        # Creates a return from the delivery picking.
        return_picking_form = Form(
            self.env['stock.return.picking'].with_context(
                active_ids=picking.ids,
                active_id=picking.id,
                active_model='stock.picking'))
        return_wizard = return_picking_form.save()
        # Checks the field `to_refund` is checked (must be checked by default).
        self.assertEqual(return_wizard.product_return_moves.to_refund, True)
        self.assertEqual(return_wizard.product_return_moves.quantity, 10)

        # Valids the return picking.
        res = return_wizard.create_returns()
        return_picking = self.env['stock.picking'].browse(res['res_id'])
        return_picking.move_lines.write({'quantity_done': 10})
        return_picking.button_validate()
        # Checks the delivery amount (must be 0).
        self.assertEqual(sale_order.order_line.qty_delivered, 0)
Esempio n. 5
0
    def test_survey_invite_token(self):
        Answer = self.env['survey.user_input']

        self.survey.write({
            'access_mode': 'token',
            'users_login_required': False
        })
        action = self.survey.action_send_survey()
        invite_form = Form(self.env[action['res_model']].with_context(
            action['context']))

        invite_form.partner_ids.add(self.customer)
        invite_form.emails = '[email protected], Raoulette Vignolette <*****@*****.**>'

        invite = invite_form.save()
        invite.action_invite()

        answers = Answer.search([('survey_id', '=', self.survey.id)])
        self.assertEqual(len(answers), 3)
        self.assertEqual(
            set(answers.mapped('email')),
            set([
                '*****@*****.**',
                '"Raoulette Vignolette" <*****@*****.**>',
                self.customer.email
            ]))
        self.assertEqual(answers.mapped('partner_id'), self.customer)
Esempio n. 6
0
    def test_production_2(self):
        """Check that confirming a production in company b with user_a will create
        stock moves on company b. """

        product_a = self.env['product.product'].create({
            'name':
            'p1',
            'company_id':
            self.company_a.id,
        })
        component_a = self.env['product.product'].create({
            'name':
            'p2',
            'company_id':
            self.company_a.id,
        })
        self.env['mrp.bom'].create({
            'product_id':
            product_a.id,
            'product_tmpl_id':
            product_a.product_tmpl_id.id,
            'company_id':
            self.company_a.id,
            'bom_line_ids': [(0, 0, {
                'product_id': component_a.id
            })]
        })
        mo_form = Form(self.env['mrp.production'].with_user(self.user_a))
        mo_form.product_id = product_a
        mo = mo_form.save()
        mo.with_user(self.user_b).action_confirm()
        self.assertEqual(mo.move_raw_ids.company_id, self.company_a)
        self.assertEqual(mo.move_finished_ids.company_id, self.company_a)
Esempio n. 7
0
    def test_survey_invite_authentication_signup(self):
        self.env["ir.config_parameter"].sudo().set_param(
            'auth_signup.invitation_scope', 'b2c')
        self.survey.invalidate_cache()
        Answer = self.env['survey.user_input']

        self.survey.write({
            'access_mode': 'public',
            'users_login_required': True
        })
        action = self.survey.action_send_survey()
        invite_form = Form(self.env[action['res_model']].with_context(
            action['context']))

        invite_form.partner_ids.add(self.customer)
        invite_form.partner_ids.add(self.user_portal.partner_id)
        invite_form.partner_ids.add(self.user_emp.partner_id)
        # TDE FIXME: not sure for emails in authentication + signup
        # invite_form.emails = '[email protected], Raoulette Vignolette <*****@*****.**>'

        invite = invite_form.save()
        invite.action_invite()

        answers = Answer.search([('survey_id', '=', self.survey.id)])
        self.assertEqual(len(answers), 3)
        self.assertEqual(
            set(answers.mapped('email')),
            set([
                self.customer.email, self.user_emp.email,
                self.user_portal.email
            ]))
        self.assertEqual(
            answers.mapped('partner_id'), self.customer
            | self.user_emp.partner_id | self.user_portal.partner_id)
Esempio n. 8
0
    def test_00_purchase_order_report(self):
        uom_dozen = self.env.ref('uom.product_uom_dozen')

        eur_currency = self.env.ref('base.EUR')
        self.company_id.currency_id = self.env.ref('base.USD').id

        self.env['res.currency.rate'].search([]).unlink()
        self.env['res.currency.rate'].create({
            'name': datetime.today(),
            'rate': 2.0,
            'currency_id': eur_currency.id,
        })
        po = self.env['purchase.order'].create({
            'partner_id': self.partner_id.id,
            'currency_id': eur_currency.id,
            'order_line': [
                (0, 0, {
                    'name': self.product1.name,
                    'product_id': self.product1.id,
                    'product_qty': 1.0,
                    'product_uom': uom_dozen.id,
                    'price_unit': 100.0,
                    'date_planned': datetime.today(),
                }),
                (0, 0, {
                    'name': self.product2.name,
                    'product_id': self.product2.id,
                    'product_qty': 1.0,
                    'product_uom': uom_dozen.id,
                    'price_unit': 200.0,
                    'date_planned': datetime.today(),
                }),
            ],
        })
        po.button_confirm()

        f = Form(self.env['account.move'].with_context(default_type='in_invoice'))
        f.partner_id = po.partner_id
        f.purchase_id = po
        invoice = f.save()
        invoice.post()
        po.flush()

        res_product1 = self.PurchaseReport.search([
            ('order_id', '=', po.id), ('product_id', '=', self.product1.id)])

        # check that report will convert dozen to unit or not
        self.assertEquals(res_product1.qty_ordered, 12.0, 'UoM conversion is not working')
        # report should show in company currency (amount/rate) = (100/2)
        self.assertEquals(res_product1.price_total, 50.0, 'Currency conversion is not working')

        res_product2 = self.PurchaseReport.search([
            ('order_id', '=', po.id), ('product_id', '=', self.product2.id)])

        # Check that repost should show 6 unit of product
        self.assertEquals(res_product2.qty_ordered, 12.0, 'UoM conversion is not working')
        # report should show in company currency (amount/rate) = (200/2)
        self.assertEquals(res_product2.price_total, 100.0, 'Currency conversion is not working')
Esempio n. 9
0
    def test_inventory_adjustment_and_negative_quants_1(self):
        """Make sure negative quants from returns get wiped out with an inventory adjustment"""
        productA = self.env['product.product'].create({
            'name': 'Product A',
            'type': 'product'
        })
        stock_location = self.env.ref('stock.stock_location_stock')
        customer_location = self.env.ref('stock.stock_location_customers')

        # Create a picking out and force availability
        picking_out = self.env['stock.picking'].create({
            'partner_id':
            self.partner.id,
            'picking_type_id':
            self.env.ref('stock.picking_type_out').id,
            'location_id':
            stock_location.id,
            'location_dest_id':
            customer_location.id,
        })
        self.env['stock.move'].create({
            'name': productA.name,
            'product_id': productA.id,
            'product_uom_qty': 1,
            'product_uom': productA.uom_id.id,
            'picking_id': picking_out.id,
            'location_id': stock_location.id,
            'location_dest_id': customer_location.id,
        })
        picking_out.action_confirm()
        picking_out.move_lines.quantity_done = 1
        picking_out.action_done()

        quant = self.env['stock.quant'].search([
            ('product_id', '=', productA.id),
            ('location_id', '=', stock_location.id)
        ])
        self.assertEqual(len(quant), 1)
        stock_return_picking_form = Form(
            self.env['stock.return.picking'].with_context(
                active_ids=picking_out.ids,
                active_id=picking_out.ids[0],
                active_model='stock.picking'))
        stock_return_picking = stock_return_picking_form.save()
        stock_return_picking.product_return_moves.quantity = 1.0
        stock_return_picking_action = stock_return_picking.create_returns()
        return_pick = self.env['stock.picking'].browse(
            stock_return_picking_action['res_id'])
        return_pick.action_assign()
        return_pick.move_lines.quantity_done = 1
        return_pick.action_done()

        quant = self.env['stock.quant'].search([
            ('product_id', '=', productA.id),
            ('location_id', '=', stock_location.id)
        ])
        self.assertEqual(sum(quant.mapped('quantity')), 0)
Esempio n. 10
0
 def test_employee_resource(self):
     _tz = 'Pacific/Apia'
     self.res_users_hr_officer.company_id.resource_calendar_id.tz = _tz
     Employee = self.env['hr.employee'].with_user(self.res_users_hr_officer)
     employee_form = Form(Employee)
     employee_form.name = 'Raoul Grosbedon'
     employee_form.work_email = '*****@*****.**'
     employee = employee_form.save()
     self.assertEqual(employee.tz, _tz)
Esempio n. 11
0
    def setUp(self):
        super(TestSubcontractingTracking, self).setUp()
        # 1: Create a subcontracting partner
        main_company_1 = self.env['res.partner'].create(
            {'name': 'main_partner'})
        self.subcontractor_partner1 = self.env['res.partner'].create({
            'name':
            'Subcontractor 1',
            'parent_id':
            main_company_1.id,
            'company_id':
            self.env.ref('base.main_company').id
        })

        # 2. Create a BOM of subcontracting type
        # 2.1. Comp1 has tracking by lot
        self.comp1_sn = self.env['product.product'].create({
            'name':
            'Component1',
            'type':
            'product',
            'categ_id':
            self.env.ref('product.product_category_all').id,
            'tracking':
            'serial'
        })
        self.comp2 = self.env['product.product'].create({
            'name':
            'Component2',
            'type':
            'product',
            'categ_id':
            self.env.ref('product.product_category_all').id,
        })

        # 2.2. Finished prodcut has tracking by serial number
        self.finished_lot = self.env['product.product'].create({
            'name':
            'finished',
            'type':
            'product',
            'categ_id':
            self.env.ref('product.product_category_all').id,
            'tracking':
            'lot'
        })
        bom_form = Form(self.env['mrp.bom'])
        bom_form.type = 'subcontract'
        bom_form.subcontractor_ids.add(self.subcontractor_partner1)
        bom_form.product_tmpl_id = self.finished_lot.product_tmpl_id
        with bom_form.bom_line_ids.new() as bom_line:
            bom_line.product_id = self.comp1_sn
            bom_line.product_qty = 1
        with bom_form.bom_line_ids.new() as bom_line:
            bom_line.product_id = self.comp2
            bom_line.product_qty = 1
        self.bom_tracked = bom_form.save()
Esempio n. 12
0
 def _produce(self, mo, quantity=0):
     produce_form = Form(self.env['mrp.product.produce'].with_context({
         'active_id':
         mo.id,
         'active_ids': [mo.id],
     }))
     if quantity:
         produce_form.qty_producing = quantity
     product_produce = produce_form.save()
     product_produce.do_produce()
Esempio n. 13
0
    def test_00_product_company_level_delays(self):
        """ In order to check schedule date, set product's Manufacturing Lead Time
            and Customer Lead Time and also set company's Manufacturing Lead Time
            and Sales Safety Days."""

        company = self.env.ref('base.main_company')

        # Update company with Manufacturing Lead Time and Sales Safety Days
        company.write({'manufacturing_lead': 3.0, 'security_lead': 3.0})

        # Create sale order of product_1
        order_form = Form(self.env['sale.order'])
        order_form.partner_id = self.partner_1
        with order_form.order_line.new() as line:
            line.product_id = self.product_1
            line.product_uom_qty = 10
        order = order_form.save()
        # Confirm sale order
        order.action_confirm()

        # Check manufacturing order created or not
        manufacturing_order = self.env['mrp.production'].search([
            ('product_id', '=', self.product_1.id),
            ('move_dest_ids', 'in', order.picking_ids[0].move_lines.ids)
        ])
        self.assertTrue(manufacturing_order,
                        'Manufacturing order should be created.')

        # Check schedule date of picking
        out_date = fields.Datetime.from_string(order.date_order) + timedelta(
            days=self.product_1.sale_delay) - timedelta(
                days=company.security_lead)
        min_date = fields.Datetime.from_string(
            order.picking_ids[0].scheduled_date)
        self.assertAlmostEqual(
            min_date,
            out_date,
            delta=timedelta(seconds=1),
            msg=
            'Schedule date of picking should be equal to: Order date + Customer Lead Time - Sales Safety Days.'
        )

        # Check schedule date of manufacturing order
        mo_date = out_date - timedelta(
            days=self.product_1.produce_delay) - timedelta(
                days=company.manufacturing_lead)
        date_deadline = fields.Datetime.from_string(
            manufacturing_order.date_deadline)
        self.assertAlmostEqual(
            date_deadline,
            mo_date,
            delta=timedelta(seconds=1),
            msg=
            "Schedule date of manufacturing order should be equal to: Schedule date of picking - product's Manufacturing Lead Time - company's Manufacturing Lead Time."
        )
Esempio n. 14
0
    def test_company_no_color_change_logo(self):
        """When neither a logo nor the colors are set
        The wizard displays the colors of the report layout
        Changing logo means the colors on the wizard change too
        Emptying the logo works and doesn't change the colors"""
        self.company.write({
            'primary_color':
            False,
            'secondary_color':
            False,
            'logo':
            False,
            'external_report_layout_id':
            self.env.ref('base.layout_template1').id,
        })
        default_colors = self.default_colors
        with Form(self.env['base.document.layout']) as doc_layout:
            self.assertColors(doc_layout, default_colors)
            self.assertEqual(doc_layout.company_id, self.company)
            doc_layout.logo = self.company_imgs['overwatch']['img']

            self.assertColors(doc_layout,
                              self.company_imgs['overwatch']['colors'])

            doc_layout.logo = ''
            self.assertColors(doc_layout,
                              self.company_imgs['overwatch']['colors'])
            self.assertEqual(doc_layout.logo, '')
Esempio n. 15
0
    def test_fifo_delivered_invoice_post_partial_delivery(self):
        """Receive 1@8, 1@10, so 2@12, standard price 12, deliver 1, invoice 2: the price used should be 10:
        one at 8 and one at 10."""
        self.product.categ_id.property_cost_method = 'fifo'
        self.product.invoice_policy = 'delivery'

        self._fifo_in_one_eight_one_ten()

        # Create and confirm a sale order for 2@12
        sale_order = self._so_and_confirm_two_units()

        # Deliver one.
        sale_order.picking_ids.move_lines.quantity_done = 1
        wiz = sale_order.picking_ids.button_validate()
        wiz = self.env[wiz['res_model']].browse(wiz['res_id'])
        wiz.process()

        # upate the standard price to 12
        self.product.standard_price = 12

        # Invoice 2
        invoice = sale_order._create_invoices()
        invoice_form = Form(invoice)
        with invoice_form.invoice_line_ids.edit(0) as invoice_line:
            invoice_line.quantity = 2
        invoice_form.save()
        invoice.post()

        # Check the resulting accounting entries
        amls = invoice.line_ids
        self.assertEqual(len(amls), 4)
        stock_out_aml = amls.filtered(
            lambda aml: aml.account_id == self.stock_output_account)
        self.assertEqual(stock_out_aml.debit, 0)
        self.assertEqual(stock_out_aml.credit, 20)
        cogs_aml = amls.filtered(
            lambda aml: aml.account_id == self.expense_account)
        self.assertEqual(cogs_aml.debit, 20)
        self.assertEqual(cogs_aml.credit, 0)
        receivable_aml = amls.filtered(
            lambda aml: aml.account_id == self.recv_account)
        self.assertEqual(receivable_aml.debit, 24)
        self.assertEqual(receivable_aml.credit, 0)
        income_aml = amls.filtered(
            lambda aml: aml.account_id == self.income_account)
        self.assertEqual(income_aml.debit, 0)
        self.assertEqual(income_aml.credit, 24)
Esempio n. 16
0
    def test_refund_cancel(self):
        """ Test invoice with a refund in 'cancel' mode, meaning a refund will be created and auto confirm to completely cancel the first
            customer invoice. The SO will have 2 invoice (customer + refund) in a paid state at the end. """
        # Increase quantity of an invoice lines
        with Form(self.invoice) as invoice_form:
            with invoice_form.invoice_line_ids.edit(0) as line_form:
                line_form.quantity = 6
            with invoice_form.invoice_line_ids.edit(1) as line_form:
                line_form.quantity = 4

        # Validate invoice
        self.invoice.post()

        # Check quantity to invoice on SO lines
        for line in self.sale_order.order_line:
            if line.product_id.invoice_policy == 'delivery':
                self.assertEquals(line.qty_to_invoice, 0.0, "Quantity to invoice should be same as ordered quantity")
                self.assertEquals(line.qty_invoiced, 0.0, "Invoiced quantity should be zero as no any invoice created for SO")
                self.assertEquals(line.untaxed_amount_to_invoice, 0.0, "The amount to invoice should be zero, as the line based on delivered quantity")
                self.assertEquals(line.untaxed_amount_invoiced, 0.0, "The invoiced amount should be zero, as the line based on delivered quantity")
                self.assertFalse(line.invoice_lines, "The line based on delivered qty are not invoiced, so they should not be linked to invoice line")
            else:
                self.assertEquals(line.untaxed_amount_to_invoice, line.price_unit * line.qty_to_invoice, "Amount to invoice is now set as qty to invoice * unit price since no price change on invoice, for ordered products")
                self.assertEquals(line.untaxed_amount_invoiced, line.price_unit * line.qty_invoiced, "Amount invoiced is now set as qty invoiced * unit price since no price change on invoice, for ordered products")
                self.assertEquals(len(line.invoice_lines), 1, "The lines 'ordered' qty are invoiced, so it should be linked to 1 invoice lines")

                self.assertEquals(line.qty_invoiced, line.product_uom_qty + 1, "The quantity invoiced is +1 unit from the one of the sale line, as we modified invoice lines (%s)" % (line.name,))
                self.assertEquals(line.qty_to_invoice, -1, "The quantity to invoice is negative as we invoice more than ordered")

        # Make a credit note
        credit_note_wizard = self.env['account.move.reversal'].with_context({'active_ids': self.invoice.ids, 'active_id': self.invoice.id, 'active_model': 'account.move'}).create({
            'refund_method': 'cancel',
            'reason': 'reason test cancel',
        })
        invoice_refund = self.env['account.move'].browse(credit_note_wizard.reverse_moves()['res_id'])

        # Check invoice's type and number
        self.assertEquals(invoice_refund.type, 'out_refund', 'The last created invoiced should be a customer invoice')
        self.assertEquals(invoice_refund.invoice_payment_state, 'paid', 'Last Customer creadit note should be in paid state')
        self.assertEquals(self.sale_order.invoice_count, 2, "The SO should have 3 related invoices: the original, the refund, and the new one")
        self.assertEquals(len(self.sale_order.invoice_ids.filtered(lambda inv: inv.type == 'out_refund')), 1, "The SO should be linked to only one refund")
        self.assertEquals(len(self.sale_order.invoice_ids.filtered(lambda inv: inv.type == 'out_invoice')), 1, "The SO should be linked to only one customer invoices")

        # At this time, the invoice 1 is opened (validated) and its refund validated too, so the amounts invoiced are zero for
        # all sale line. All invoiceable Sale lines have
        for line in self.sale_order.order_line:
            if line.product_id.invoice_policy == 'delivery':
                self.assertEquals(line.qty_to_invoice, 0.0, "Quantity to invoice should be same as ordered quantity")
                self.assertEquals(line.qty_invoiced, 0.0, "Invoiced quantity should be zero as no any invoice created for SO line based on delivered qty")
                self.assertEquals(line.untaxed_amount_to_invoice, 0.0, "The amount to invoice should be zero, as the line based on delivered quantity")
                self.assertEquals(line.untaxed_amount_invoiced, 0.0, "The invoiced amount should be zero, as the line based on delivered quantity")
                self.assertFalse(line.invoice_lines, "The line based on delivered are not invoiced, so they should not be linked to invoice line")
            else:
                self.assertEquals(line.qty_to_invoice, line.product_uom_qty, "The quantity to invoice should be the ordered quantity")
                self.assertEquals(line.qty_invoiced, 0, "The quantity invoiced is zero as the refund (paid) completely cancel the first invoice")

                self.assertEquals(line.untaxed_amount_to_invoice, line.price_unit * line.qty_to_invoice, "Amount to invoice is now set as qty to invoice * unit price since no price change on invoice, for ordered products")
                self.assertEquals(line.untaxed_amount_invoiced, line.price_unit * line.qty_invoiced, "Amount invoiced is now set as qty invoiced * unit price since no price change on invoice, for ordered products")
                self.assertEquals(len(line.invoice_lines), 2, "The lines 'ordered' qty are invoiced, so it should be linked to 1 invoice lines")
Esempio n. 17
0
 def test_02_warehouse_twostep_manufacturing(self):
     """ Warehouse testing for picking ans store after manufacturing """
     with Form(self.warehouse) as warehouse:
         warehouse.manufacture_steps = 'pbm_sam'
     self._check_location_and_routes()
     self.assertEqual(len(self.warehouse.pbm_route_id.rule_ids), 3)
     self.assertEqual(self.warehouse.manufacture_pull_id.location_id.id,
                      self.warehouse.sam_loc_id.id)
Esempio n. 18
0
 def test_01_warehouse_twostep_manufacturing(self):
     """ Warehouse testing for picking before manufacturing """
     with Form(self.warehouse) as warehouse:
         warehouse.manufacture_steps = 'pbm'
     self._check_location_and_routes()
     self.assertEqual(len(self.warehouse.pbm_route_id.rule_ids), 2)
     self.assertEqual(self.warehouse.manufacture_pull_id.location_id.id,
                      self.warehouse.lot_stock_id.id)
Esempio n. 19
0
    def test_pricelist_application(self):
        """ Test different prices are correctly applied based on dates """
        support_product = self.env.ref('product.product_product_2')
        support_product.list_price = 100
        partner = self.res_partner_model.create(dict(name="George"))

        christmas_pricelist = self.env['product.pricelist'].create({
            'name':
            'Christmas pricelist',
            'item_ids': [(0, 0, {
                'date_start': "2017-12-01",
                'date_end': "2017-12-24",
                'compute_price': 'percentage',
                'base': 'list_price',
                'percent_price': 20,
                'applied_on': '3_global',
                'name': 'Pre-Christmas discount'
            }),
                         (0, 0, {
                             'date_start': "2017-12-25",
                             'date_end': "2017-12-31",
                             'compute_price': 'percentage',
                             'base': 'list_price',
                             'percent_price': 50,
                             'applied_on': '3_global',
                             'name': 'Post-Christmas super-discount'
                         })]
        })

        # Create the SO with pricelist based on date
        order_form = Form(
            self.env['sale.order'].with_context(tracking_disable=True))
        order_form.partner_id = partner
        order_form.date_order = '2017-12-20'
        order_form.pricelist_id = christmas_pricelist
        with order_form.order_line.new() as line:
            line.product_id = support_product
        so = order_form.save()
        # Check the unit price and subtotal of SO line
        self.assertEqual(so.order_line[0].price_unit, 80,
                         "First date pricelist rule not applied")
        self.assertEquals(
            so.order_line[0].price_subtotal,
            so.order_line[0].price_unit * so.order_line[0].product_uom_qty,
            'Total of SO line should be a multiplication of unit price and ordered quantity'
        )

        # Change order date of the SO and check the unit price and subtotal of SO line
        with Form(so) as order:
            order.date_order = '2017-12-30'
            with order.order_line.edit(0) as line:
                line.product_id = support_product

        self.assertEqual(so.order_line[0].price_unit, 50,
                         "Second date pricelist rule not applied")
        self.assertEquals(
            so.order_line[0].price_subtotal,
            so.order_line[0].price_unit * so.order_line[0].product_uom_qty,
            'Total of SO line should be a multiplication of unit price and ordered quantity'
        )
Esempio n. 20
0
    def test_no_expense(self):
        """ Test invoicing vendor bill with no policy. Check nothing happen. """
        # confirm SO
        sale_order_line = self.env['sale.order.line'].create({
            'name':
            self.product_no_expense.name,
            'product_id':
            self.product_no_expense.id,
            'product_uom_qty':
            2,
            'qty_delivered':
            1,
            'product_uom':
            self.product_no_expense.uom_id.id,
            'price_unit':
            self.product_no_expense.list_price,
            'order_id':
            self.sale_order.id,
        })
        self.sale_order._compute_tax_id()
        self.sale_order.action_confirm()

        # create invoice lines and validate it
        move_form = Form(self.AccountMove)
        move_form.partner_id = self.partner_customer_usd
        move_form.journal_id = self.journal_purchase
        with move_form.line_ids.new() as line_form:
            line_form.product_id = self.product_no_expense
            line_form.quantity = 3.0
            line_form.analytic_account_id = self.analytic_account
        invoice_a = move_form.save()
        invoice_a.post()

        self.assertEquals(
            len(self.sale_order.order_line), 1,
            "No SO line should have been created (or removed) when validating vendor bill"
        )
        self.assertEquals(
            sale_order_line.qty_delivered, 1,
            "The delivered quantity of SO line should not have been incremented"
        )
        self.assertTrue(invoice_a.mapped('line_ids.analytic_line_ids'),
                        "Analytic lines should be generated")
Esempio n. 21
0
    def create_account_invoice(self,
                               invoice_type,
                               partner,
                               product,
                               quantity=0.0,
                               price_unit=0.0):
        """ Create an invoice as in a view by triggering its onchange methods"""

        invoice_form = Form(
            self.env['account.move'].with_context(default_type=invoice_type))
        invoice_form.partner_id = partner
        with invoice_form.invoice_line_ids.new() as line:
            line.product_id = product
            line.quantity = quantity
            line.price_unit = price_unit

        invoice = invoice_form.save()
        invoice.post()
        return invoice
Esempio n. 22
0
 def test_00_create_warehouse(self):
     """ Warehouse testing for direct manufacturing """
     with Form(self.warehouse) as warehouse:
         warehouse.manufacture_steps = 'mrp_one_step'
     self._check_location_and_routes()
     # Check locations of existing pull rule
     self.assertFalse(
         self.warehouse.pbm_route_id.rule_ids,
         'only the update of global manufacture route should happen.')
     self.assertEqual(self.warehouse.manufacture_pull_id.location_id.id,
                      self.warehouse.lot_stock_id.id)
Esempio n. 23
0
    def test_procurement_2(self):
        """Check that a manufacturing order create the right procurements when the route are set on
        a parent category of a product"""
        # find a child category id
        all_categ_id = self.env['product.category'].search(
            [('parent_id', '=', None)], limit=1)
        child_categ_id = self.env['product.category'].search(
            [('parent_id', '=', all_categ_id.id)], limit=1)

        # set the product of `self.bom_1` to this child category
        for bom_line_id in self.bom_1.bom_line_ids:
            # check that no routes are defined on the product
            self.assertEquals(len(bom_line_id.product_id.route_ids), 0)
            # set the category of the product to a child category
            bom_line_id.product_id.categ_id = child_categ_id

        # set the MTO route to the parent category (all)
        self.warehouse = self.env.ref('stock.warehouse0')
        mto_route = self.warehouse.mto_pull_id.route_id
        mto_route.product_categ_selectable = True
        all_categ_id.write({'route_ids': [(6, 0, [mto_route.id])]})

        # create MO, but check it raises error as components are in make to order and not everyone has
        with self.assertRaises(UserError):
            production_form = Form(self.env['mrp.production'])
            production_form.product_id = self.product_4
            production_form.product_uom_id = self.product_4.uom_id
            production_form.product_qty = 1
            production_product_4 = production_form.save()
            production_product_4.action_confirm()
Esempio n. 24
0
    def test_company_colors_change_logo(self):
        """changes of the logo implies displaying the new computed colors"""
        self.company.write({
            'primary_color': '#ff0080',
            'secondary_color': '#00ff00',
            'logo': False,
        })

        with Form(self.env['base.document.layout']) as doc_layout:
            self.assertColors(doc_layout, self.company)
            doc_layout.logo = self.company_imgs['coffice']['img']
            self.assertColors(doc_layout,
                              self.company_imgs['coffice']['colors'])
Esempio n. 25
0
 def _make_mo(self, bom, quantity=1):
     mo_form = Form(self.env['mrp.production'])
     mo_form.product_id = bom.product_id
     mo_form.bom_id = bom
     mo_form.product_qty = quantity
     mo = mo_form.save()
     mo.action_confirm()
     return mo
Esempio n. 26
0
    def test_no_expense(self):
        """ Test invoicing vendor bill with no policy. Check nothing happen. """
        # confirm SO
        sale_order_line = self.env['sale.order.line'].create({
            'name': self.product_no_expense.name,
            'product_id': self.product_no_expense.id,
            'product_uom_qty': 2,
            'qty_delivered': 1,
            'product_uom': self.product_no_expense.uom_id.id,
            'price_unit': self.product_no_expense.list_price,
            'order_id': self.sale_order.id,
        })
        self.sale_order._compute_tax_id()
        self.sale_order.action_confirm()

        # create invoice lines and validate it
        move_form = Form(self.env['account.move'].with_context(default_type='in_invoice'))
        move_form.partner_id = self.partner_customer_usd
        with move_form.line_ids.new() as line_form:
            line_form.product_id = self.product_no_expense
            line_form.quantity = 3.0
            line_form.analytic_account_id = self.analytic_account
        invoice_a = move_form.save()
        invoice_a.post()

        # let's log some timesheets (on the project created by sale_order_line1)
        task_sol1 = sale_order_line.task_id
        self.env['account.analytic.line'].create({
            'name': 'Test Line',
            'project_id': task_sol1.project_id.id,
            'task_id': task_sol1.id,
            'unit_amount': 1,
            'employee_id': self.employee_user.id,
        })

        self.assertEquals(len(self.sale_order.order_line), 1, "No SO line should have been created (or removed) when validating vendor bill")
        self.assertEquals(sale_order_line.qty_delivered, 1, "The delivered quantity of SO line should not have been incremented")
        self.assertTrue(invoice_a.mapped('line_ids.analytic_line_ids'), "Analytic lines should be generated")
Esempio n. 27
0
    def test_readonly_fields(self):
        """ Employee related fields should be readonly if self editing is not allowed """
        self.env['ir.config_parameter'].sudo().set_param('hr.hr_employee_self_edit', False)
        james = new_test_user(self.env, login='******', groups='base.group_user', name='Simple employee', email='*****@*****.**')
        james = james.with_user(james)
        self.env['hr.employee'].create({
            'name': 'James',
            'user_id': james.id,
        })

        view = self.env.ref('hr.res_users_view_form_profile')
        view_infos = james.fields_view_get(view_id=view.id)

        employee_related_fields = {
            field_name
            for field_name, field_attrs in view_infos['fields'].items()
            if field_attrs.get('related', (None,))[0] == 'employee_id'
        }

        form = Form(james, view=view)
        for field in employee_related_fields:
            with self.assertRaises(AssertionError, msg="Field '%s' should be readonly in the employee profile when self edition is not allowed." % field):
                form.__setattr__(field, 'some value')
Esempio n. 28
0
    def setUp(self):
        super(TestSaleMrpLeadTime, self).setUp()

        # Update the product_1 with type, route, Manufacturing Lead Time and Customer Lead Time
        with Form(self.product_1) as p1:
            p1.type = 'product'
            p1.produce_delay = 5.0
            p1.sale_delay = 5.0
            p1.route_ids.clear()
            p1.route_ids.add(self.warehouse_1.manufacture_pull_id.route_id)
            p1.route_ids.add(self.warehouse_1.mto_pull_id.route_id)

        # Update the product_2 with type
        with Form(self.product_2) as p2:
            p2.type = 'consu'

        # Create Bill of materials for product_1
        with Form(self.env['mrp.bom']) as bom:
            bom.product_tmpl_id = self.product_1.product_tmpl_id
            bom.product_qty = 2
            with bom.bom_line_ids.new() as line:
                line.product_id = self.product_2
                line.product_qty = 4
Esempio n. 29
0
    def test_company_no_color_but_logo_change_logo(self):
        """When company colors are not set, but a logo is,
        the wizard displays the computed colors from the logo"""
        self.company.write({
            'primary_color': '#ff0080',
            'secondary_color': '#00ff00',
            'logo': self.company_imgs['overwatch']['img'],
        })

        with Form(self.env['base.document.layout']) as doc_layout:
            self.assertColors(doc_layout, self.company)
            doc_layout.logo = self.company_imgs['coffice']['img']
            self.assertColors(doc_layout,
                              self.company_imgs['coffice']['colors'])
Esempio n. 30
0
 def new_mo_laptop(self):
     form = Form(self.env['mrp.production'])
     form.product_id = self.laptop
     form.product_qty = 1
     form.bom_id = self.bom_laptop
     p = form.save()
     p.action_confirm()
     p.action_assign()
     return p