Exemple #1
0
    def test_sale_mrp(self):
        warehouse0 = self.env.ref('stock.warehouse0')
        # In order to test the sale_mrp module in OpenERP, I start by creating a new product 'Slider Mobile'
        # I define product category Mobile Products Sellable.

        with mute_logger('swerp.tests.common.onchange'):
            # Suppress warning on "Changing your cost method" when creating a
            # product category
            pc = Form(self.env['product.category'])
        pc.name = 'Mobile Products Sellable'
        product_category_allproductssellable0 = pc.save()

        uom_unit = self.env.ref('uom.product_uom_unit')

        self.assertIn("seller_ids", self.env['product.template'].fields_get())

        # I define product for Slider Mobile.
        product = Form(self.env['product.template'])

        product.categ_id = product_category_allproductssellable0
        product.list_price = 200.0
        product.name = 'Slider Mobile'
        product.standard_price = 189.0
        product.type = 'product'
        product.uom_id = uom_unit
        product.uom_po_id = uom_unit
        product.route_ids.clear()
        product.route_ids.add(warehouse0.manufacture_pull_id.route_id)
        product.route_ids.add(warehouse0.mto_pull_id.route_id)
        product_template_slidermobile0 = product.save()

        with Form(self.env['mrp.bom']) as bom:
            bom.product_tmpl_id = product_template_slidermobile0

        # I create a sale order for product Slider mobile
        so_form = Form(self.env['sale.order'])
        so_form.partner_id = self.env.ref('base.res_partner_4')
        with so_form.order_line.new() as line:
            line.product_id = product_template_slidermobile0.product_variant_ids
            line.price_unit = 200
            line.product_uom_qty = 500.0
            line.customer_lead = 7.0
        sale_order_so0 = so_form.save()

        # I confirm the sale order
        sale_order_so0.action_confirm()

        # I verify that a manufacturing order has been generated, and that its name and reference are correct
        mo = self.env['mrp.production'].search(
            [('origin', 'like', sale_order_so0.name)], limit=1)
        self.assertTrue(mo, 'Manufacturing order has not been generated')
Exemple #2
0
    def test_state(self):
        # In order to test Confirm Draft Invoice wizard I create an invoice
        # and confirm it with this wizard
        f = Form(self.env['account.invoice'])
        f.partner_id = self.env.ref('base.res_partner_12')
        with f.invoice_line_ids.new() as l:
            l.product_id = self.env.ref('product.product_product_3')
        invoice = f.save()

        # I check that Initially customer invoice state is "Draft"
        self.assertEqual(invoice.state, 'draft')

        # I called the "Confirm Draft Invoices" wizard
        w = Form(self.env['account.invoice.confirm']).save()
        # I clicked on Confirm Invoices Button
        w.with_context(
            active_model='account.invoice',
            active_id=invoice.id,
            active_ids=invoice.ids,
            type='out_invoice',
        ).invoice_confirm()

        # I check that customer invoice state is "Open"
        self.assertEqual(invoice.state, 'open')

        # I check the journal associated and put this journal as not
        moves = self.env['account.move.line'].search([('invoice_id', '=',
                                                       invoice.id)])
        self.assertGreater(len(moves), 0, 'You should have multiple moves')
        moves[0].journal_id.write({'update_posted': True})

        # I cancelled this open invoice using the button on invoice
        invoice.action_invoice_cancel()
        # I check that customer invoice is in the cancel state
        self.assertEqual(invoice.state, 'cancel')
 def test_allocation_request(self):
     """ Create an allocation request """
     # employee should be set to current user
     allocation_form = Form(self.env['hr.leave.allocation'].sudo(
         self.user_employee))
     allocation_form.holiday_status_id = self.holidays_type_1
     allocation = allocation_form.save()
 def _create_invoice_from_file(self, attachment):
     self = self.with_context(default_journal_id=self.journal_id.id)
     invoice_form = Form(self.env['account.invoice'],
                         view='account.invoice_supplier_form')
     invoice = invoice_form.save()
     attachment.write({
         'res_model': 'account.invoice',
         'res_id': invoice.id
     })
     invoice.message_post(attachment_ids=[attachment.id])
     return invoice
Exemple #5
0
    def test_basic(self):
        env = self.env(context=dict(self.env.context, journal_type='bank'))

        # select the period and journal for the bank statement
        journal = env['account.bank.statement'].with_context(
            date=time.strftime("%Y/%m/%d"),  # ???
        )._default_journal()
        self.assertTrue(journal, 'Journal has not been selected')

        f = Form(env['account.bank.statement'])
        # necessary as there may be existing bank statements with a non-zero
        # closing balance which will be used to initialise this one.
        f.balance_start = 0.0
        f.balance_end_real = 0.0
        with f.line_ids.new() as line:
            line.name = 'EXT001'
            line.amount = 1000
            line.partner_id = env.ref('base.res_partner_4')

        statement_id = f.save()

        # process the bank statement line
        account = env['account.account'].create({
            'name':
            'toto',
            'code':
            'bidule',
            'user_type_id':
            env.ref('account.data_account_type_fixed_assets').id
        })
        statement_id.line_ids[0].process_reconciliation(
            new_aml_dicts=[{
                'credit': 1000,
                'debit': 0,
                'name': 'toto',
                'account_id': account.id,
            }])

        with Form(statement_id) as f:
            # modify the bank statement and set the Ending Balance.
            f.balance_end_real = 1000.0

        # confirm the bank statement using Validate button
        statement_id.button_confirm_bank()

        self.assertEqual(statement_id.state, 'confirm')
 def test_department_leave(self):
     """ Create a department leave """
     self.employee_hrmanager.write({'department_id': self.hr_dept.id})
     self.assertFalse(self.env['hr.leave'].search([
         ('employee_id', 'in', self.hr_dept.member_ids.ids)
     ]))
     leave_form = Form(self.env['hr.leave'].sudo(self.user_hrmanager))
     leave_form.holiday_type = 'department'
     leave_form.department_id = self.hr_dept
     leave_form.holiday_status_id = self.holidays_type_1
     leave = leave_form.save()
     leave.action_approve()
     member_ids = self.hr_dept.member_ids.ids
     self.assertEqual(
         self.env['hr.leave'].search_count([('employee_id', 'in',
                                             member_ids)]), len(member_ids),
         "Leave should be created for members of department")
    def test_06_differed_schedule_date(self):
        warehouse = self.env['stock.warehouse'].search([], limit=1)
        with Form(warehouse) as w:
            w.reception_steps = 'three_steps'
        po_form = Form(self.env['purchase.order'])
        po_form.partner_id = self.partner_id
        with po_form.order_line.new() as line:
            line.product_id = self.product_id_1
            line.date_planned = datetime.today()
            line.product_qty = 1.0
        with po_form.order_line.new() as line:
            line.product_id = self.product_id_1
            line.date_planned = datetime.today() + timedelta(days=7)
            line.product_qty = 1.0
        po = po_form.save()
        po.button_approve()

        po.picking_ids.move_line_ids.write({'qty_done': 1.0})
        po.picking_ids.action_done()
        pickings = self.env['stock.picking'].search([('group_id', '=',
                                                      po.group_id.id)])
        for picking in pickings:
            self.assertEqual(picking.scheduled_date.date(), date.today())
    def test_onchange_taxes_2(self):
        '''
        Test the amount of tax account.move.line is adapted when editing the account.move.line amount.
        This test uses the following scenario:
            - Create manually a debit line of 1000 having a tax.
            - Assume a line containing the tax amount is created automatically.
            - Set the debit amount to 2000 in the first created line.
            - Assume the line containing the tax amount has been updated automatically.
            - Create manually a credit line to balance the two previous lines.
            - Save the move.

        tax = 10%

        Name            | Debit     | Credit    | Tax_ids       | Tax_line_id's name
        ----------------|-----------|-----------|---------------|-------------------
        debit_line_1    | 2000      |           | tax           |
        tax_line        | 200       |           |               | tax_line
        debit_line_1    |           | 2200      |               |
        '''
        move_form = Form(self.env['account.move'],
                         view='account.view_move_form')
        move_form.ref = 'azerty'
        move_form.journal_id = self.journal

        # Create a new account.move.line with debit amount.
        with move_form.line_ids.new() as debit_line:
            debit_line.name = 'debit_line_1'
            debit_line.account_id = self.account
            debit_line.debit = 1000
            debit_line.tax_ids.clear()
            debit_line.tax_ids.add(self.percent_tax)

            self.assertTrue(debit_line.recompute_tax_line)

            debit_line.debit = 2000

            self.assertTrue(debit_line.recompute_tax_line)

        # Create a third account.move.line with credit amount.
        with move_form.line_ids.new() as credit_line:
            credit_line.name = 'credit_line_1'
            credit_line.account_id = self.account
            credit_line.credit = 2200

        move = move_form.save()

        self.assertRecordValues(move.line_ids, [
            {
                'name': 'credit_line_1',
                'debit': 0.0,
                'credit': 2200.0,
                'tax_ids': [],
                'tax_line_id': False
            },
            {
                'name': 'tax_line',
                'debit': 200.0,
                'credit': 0.0,
                'tax_ids': [],
                'tax_line_id': self.percent_tax.id
            },
            {
                'name': 'debit_line_1',
                'debit': 2000.0,
                'credit': 0.0,
                'tax_ids': [self.percent_tax.id],
                'tax_line_id': False
            },
        ])
    def test_onchange_taxes_3(self):
        '''
        Test the amount of tax account.move.line is still editable manually.
        Test the amount of tax account.move.line is cumulative for the same tax.
        This test uses the following scenario:
            - Create manually a debit line of 1000 having a tax.
            - Assume a line containing the tax amount is created automatically.
            - Edit the tax line amount of the auto-generated line by adding 5.
            - Create manually a credit line to balance the two previous lines.
            - Save the move.
            - Edit the move.
            - Create manually a debit line of 2000 having the same tax.
            - Assume the line containing the tax amount has been updated (no new line created).
            - Create manually a credit line to balance the four previous lines.
            - Save the move.

        tax = 10%

        Name            | Debit     | Credit    | Tax_ids       | Tax_line_id's name
        ----------------|-----------|-----------|---------------|-------------------
        debit_line_1    | 1000      |           | tax           |
        tax_line        | 300       |           |               | tax_line
        credit_line_1   |           | 1105      |               |
        debit_line_2    | 2000      |           | tax           |
        credit_line_2   |           | 2195      |               |
        '''
        move_form = Form(self.env['account.move'],
                         view='account.view_move_form')
        move_form.ref = 'azerty'
        move_form.journal_id = self.journal

        # Create a new account.move.line with debit amount.
        with move_form.line_ids.new() as debit_line:
            debit_line.name = 'debit_line_1'
            debit_line.account_id = self.account
            debit_line.debit = 1000
            debit_line.tax_ids.clear()
            debit_line.tax_ids.add(self.percent_tax)

            self.assertTrue(debit_line.recompute_tax_line)

        # Edit the tax account.move.line
        with move_form.line_ids.edit(index=1) as tax_line:
            tax_line.debit = 105  # Was 100

        # Create a third account.move.line with credit amount.
        with move_form.line_ids.new() as credit_line:
            credit_line.name = 'credit_line_1'
            credit_line.account_id = self.account
            credit_line.credit = 1105

        move = move_form.save()

        move_form = Form(move, view='account.view_move_form')
        # Create a new account.move.line with debit amount.
        with move_form.line_ids.new() as debit_line2:
            debit_line2.name = 'debit_line_2'
            debit_line2.account_id = self.account
            debit_line2.debit = 2000
            debit_line2.tax_ids.clear()
            debit_line2.tax_ids.add(self.percent_tax)

            self.assertTrue(debit_line2.recompute_tax_line)

        with move_form.line_ids.new() as credit_line2:
            credit_line2.name = 'credit_line_2'
            credit_line2.account_id = self.account
            credit_line2.credit = 2195

        move = move_form.save()

        self.assertRecordValues(move.line_ids, [
            {
                'name': 'credit_line_2',
                'debit': 0.0,
                'credit': 2195.0,
                'tax_ids': [],
                'tax_line_id': False
            },
            {
                'name': 'debit_line_2',
                'debit': 2000.0,
                'credit': 0.0,
                'tax_ids': [self.percent_tax.id],
                'tax_line_id': False
            },
            {
                'name': 'credit_line_1',
                'debit': 0.0,
                'credit': 1105.0,
                'tax_ids': [],
                'tax_line_id': False
            },
            {
                'name': 'tax_line',
                'debit': 300.0,
                'credit': 0.0,
                'tax_ids': [],
                'tax_line_id': self.percent_tax.id
            },
            {
                'name': 'debit_line_1',
                'debit': 1000.0,
                'credit': 0.0,
                'tax_ids': [self.percent_tax.id],
                'tax_line_id': False
            },
        ])
Exemple #10
0
    def test_sale_mrp_pickings(self):
        """ Test sale of multiple mrp products in MTO
        to avoid generating multiple deliveries
        to the customer location
        """

        # Create warehouse
        self.customer_location = self.env['ir.model.data'].xmlid_to_res_id(
            'stock.stock_location_customers')
        warehouse_form = Form(self.env['stock.warehouse'])
        warehouse_form.name = 'Test Warehouse'
        warehouse_form.code = 'TWH'
        self.warehouse = warehouse_form.save()

        self.uom_unit = self.env.ref('uom.product_uom_unit')

        # Create raw product for manufactured product
        product_form = Form(self.env['product.product'])
        product_form.name = 'Raw Stick'
        product_form.type = 'product'
        product_form.uom_id = self.uom_unit
        product_form.uom_po_id = self.uom_unit
        self.raw_product = product_form.save()

        # Create manufactured product
        product_form = Form(self.env['product.product'])
        product_form.name = 'Stick'
        product_form.uom_id = self.uom_unit
        product_form.uom_po_id = self.uom_unit
        product_form.type = 'product'
        product_form.route_ids.clear()
        product_form.route_ids.add(self.warehouse.manufacture_pull_id.route_id)
        product_form.route_ids.add(self.warehouse.mto_pull_id.route_id)
        self.finished_product = product_form.save()

        # Create manifactured product which uses another manifactured
        product_form = Form(self.env['product.product'])
        product_form.name = 'Arrow'
        product_form.type = 'product'
        product_form.route_ids.clear()
        product_form.route_ids.add(self.warehouse.manufacture_pull_id.route_id)
        product_form.route_ids.add(self.warehouse.mto_pull_id.route_id)
        self.complex_product = product_form.save()

        ## Create raw product for manufactured product
        product_form = Form(self.env['product.product'])
        product_form.name = 'Raw Iron'
        product_form.type = 'product'
        product_form.uom_id = self.uom_unit
        product_form.uom_po_id = self.uom_unit
        self.raw_product_2 = product_form.save()

        # Create bom for manufactured product
        bom_product_form = Form(self.env['mrp.bom'])
        bom_product_form.product_id = self.finished_product
        bom_product_form.product_tmpl_id = self.finished_product.product_tmpl_id
        bom_product_form.product_qty = 1.0
        bom_product_form.type = 'normal'
        with bom_product_form.bom_line_ids.new() as bom_line:
            bom_line.product_id = self.raw_product
            bom_line.product_qty = 2.0

        self.bom = bom_product_form.save()

        ## Create bom for manufactured product
        bom_product_form = Form(self.env['mrp.bom'])
        bom_product_form.product_id = self.complex_product
        bom_product_form.product_tmpl_id = self.complex_product.product_tmpl_id
        with bom_product_form.bom_line_ids.new() as line:
            line.product_id = self.finished_product
            line.product_qty = 1.0
        with bom_product_form.bom_line_ids.new() as line:
            line.product_id = self.raw_product_2
            line.product_qty = 1.0

        self.complex_bom = bom_product_form.save()

        with Form(self.warehouse) as warehouse:
            warehouse.manufacture_steps = 'pbm_sam'

        so_form = Form(self.env['sale.order'])
        so_form.partner_id = self.env.ref('base.res_partner_4')
        with so_form.order_line.new() as line:
            line.product_id = self.complex_product
            line.price_unit = 1
            line.product_uom_qty = 1
        with so_form.order_line.new() as line:
            line.product_id = self.finished_product
            line.price_unit = 1
            line.product_uom_qty = 1
        sale_order_so0 = so_form.save()

        sale_order_so0.action_confirm()

        pickings = sale_order_so0.picking_ids

        # One delivery...
        self.assertEqual(len(pickings), 1)

        # ...with two products
        move_lines = pickings[0].move_lines
        self.assertEqual(len(move_lines), 2)