def _create_delivery(self): picking_type = self.env['stock.picking.type'].search( [('code', '=', 'outgoing'), '|', ('warehouse_id.company_id', '=', self.company.id), ('warehouse_id', '=', False)], limit=1, ) picking_form = Form( recordp=self.env['stock.picking'].with_context( default_picking_type_id=picking_type.id), view="stock.view_picking_form", ) picking_form.company_id = self.company picking_form.partner_id = self.partner with picking_form.move_ids_without_package.new() as move: move.product_id = self.product move.product_uom_qty = 10 with picking_form.move_ids_without_package.new() as move: move.product_id = self.product_product.create({ 'name': 'Product 2 test', 'type': 'product' }) move.product_uom_qty = 20 picking = picking_form.save() picking.action_confirm() for move in picking.move_lines: move.quantity_done = move.product_uom_qty picking.button_validate() return picking
def test_partner_3(self): """ Create a new partner, select a parent company, and choose type subcontractor (debug active). Checks the onchange correctly set the customer and supplier locations to the subcontracting ones. Change them to another one, save, checks they are rightly applied. """ # FIXME sle: this field should not be writeable without the debug mode but it is. ask xmo group_no_one = self.env.ref('base.group_no_one') self.env.user.write({'groups_id': [(3, group_no_one.id)]}) partner_form = Form(self.env['res.partner']) partner_form.name = 'subcontractor partner' partner_form.company_id = self.env.ref('base.main_company') self.assertNotEqual( partner_form.property_stock_supplier, self.env.user.company_id.subcontracting_location_id) self.assertNotEqual( partner_form.property_stock_customer, self.env.user.company_id.subcontracting_location_id) partner_form.type = 'subcontractor' self.assertEqual(partner_form.property_stock_supplier, self.env.user.company_id.subcontracting_location_id) self.assertEqual(partner_form.property_stock_customer, self.env.user.company_id.subcontracting_location_id) subcontracting_location2 = self.env.user.company_id.subcontracting_location_id.copy( ) partner_form.property_stock_supplier = subcontracting_location2 partner_form.property_stock_customer = subcontracting_location2 partner = partner_form.save() self.assertEqual(partner.property_stock_supplier, subcontracting_location2) self.assertEqual(partner.property_stock_customer, subcontracting_location2)
def test_onchange(self): rma_form = Form(self.env['rma']) # If partner changes, the invoice address is set rma_form.partner_id = self.partner self.assertEqual(rma_form.partner_invoice_id, self.partner_invoice) # If origin move changes, the product is set uom_ten = self.env['uom.uom'].create({ 'name': "Ten", 'category_id': self.env.ref('uom.product_uom_unit').id, 'factor_inv': 10, 'uom_type': 'bigger', }) product_2 = self.product_product.create({ 'name': 'Product test 2', 'type': 'product', 'uom_id': uom_ten.id, }) outgoing_picking_type = self.env['stock.picking.type'].search( [('code', '=', 'outgoing'), '|', ('warehouse_id.company_id', '=', self.company.id), ('warehouse_id', '=', False)], limit=1, ) picking_form = Form( recordp=self.env['stock.picking'].with_context( default_picking_type_id=outgoing_picking_type.id), view="stock.view_picking_form", ) picking_form.company_id = self.company picking_form.partner_id = self.partner picking_form.partner_id = self.partner with picking_form.move_ids_without_package.new() as move: move.product_id = product_2 move.product_uom_qty = 15 move.product_uom = uom_ten picking = picking_form.save() picking.action_done() rma_form.picking_id = picking rma_form.move_id = picking.move_lines self.assertEqual(rma_form.product_id, product_2) self.assertEqual(rma_form.product_uom_qty, 15) self.assertEqual(rma_form.product_uom, uom_ten) # If product changes, unit of measure changes rma_form.picking_id = self.env['stock.picking'] rma_form.product_id = self.product self.assertEqual(rma_form.product_id, self.product) self.assertEqual(rma_form.product_uom_qty, 15) self.assertNotEqual(rma_form.product_uom, uom_ten) self.assertEqual(rma_form.product_uom, self.product.uom_id) rma = rma_form.save() # If product changes, unit of measure domain should also change domain = rma._onchange_product_id()['domain']['product_uom'] self.assertListEqual( domain, [('category_id', '=', self.product.uom_id.category_id.id)])
def test_create(self): expected_date = fields.Datetime.now() order_vals = { "company_id": self.main_company.id, "warehouse_id": self.warehouse.id, "location_id": self.warehouse.lot_stock_id.id, "expected_date": expected_date, "stock_request_ids": [( 0, 0, { "product_id": self.product.id, "product_uom_id": self.product.uom_id.id, "product_uom_qty": 5.0, "company_id": self.main_company.id, "warehouse_id": self.warehouse.id, "location_id": self.warehouse.lot_stock_id.id, "expected_date": expected_date, }, )], } form = Form(self.env["stock.request.order"]) form.company_id = self.main_company form.expected_date = expected_date # test _getdefault_picking_type() self.assertEqual(form.picking_type_id, self.default_picking_type) form.warehouse_id = self.warehouse form.location_id = self.warehouse.lot_stock_id new_pick_type = (self.env["stock.picking.type"].with_context( company_id=self.main_company.id).create({ "name": "Stock Request wh", "sequence_id": self.env.ref("stock_request.seq_stock_request_order").id, "code": "stock_request_order", "sequence_code": "SRO", "warehouse_id": self.warehouse.id, })) order = self.request_order.with_user( self.stock_request_user).create(order_vals) # test create() self.assertEqual(order.picking_type_id, new_pick_type)
def test_lot_onchange_product_id(self): product = self.product_product.create( dict(name="Shiba plush", tracking="lot")) product.lot_sequence_id.write( dict(prefix="shiba/", padding=4, number_increment=1, number_next_actual=1)) lot_form = Form(self.stock_production_lot) lot_form.product_id = product lot_form.company_id = self.env.company lot = lot_form.save() self.assertRegexpMatches(lot.name, r"shiba/\d{4}$")
def test_05_config_settings(self): self.env.company.default_spread_revenue_account_id = self.account_revenue self.env.company.default_spread_expense_account_id = self.account_payable self.env.company.default_spread_revenue_journal_id = self.sales_journal self.env.company.default_spread_expense_journal_id = self.expenses_journal self.assertTrue(self.env.company.default_spread_revenue_account_id) self.assertTrue(self.env.company.default_spread_expense_account_id) self.assertTrue(self.env.company.default_spread_revenue_journal_id) self.assertTrue(self.env.company.default_spread_expense_journal_id) spread_form = Form(self.env["account.spread"]) spread_form.name = "test" spread_form.invoice_type = "in_invoice" spread_form.debit_account_id = self.debit_account spread_form.credit_account_id = self.credit_account spread = spread_form.save() self.assertTrue(spread) self.assertFalse(spread.line_ids) self.assertFalse(spread.invoice_line_ids) self.assertFalse(spread.invoice_line_id) self.assertFalse(spread.invoice_id) self.assertFalse(spread.account_analytic_id) self.assertFalse(spread.analytic_tag_ids) self.assertTrue(spread.move_line_auto_post) defaults = self.env["account.spread"].default_get(["company_id", "currency_id"]) self.assertEqual(defaults["company_id"], self.env.company.id) self.assertEqual(defaults["currency_id"], self.env.company.currency_id.id) spread_form = Form(spread) spread_form.invoice_type = "out_invoice" spread_form.company_id = self.env.company spread = spread_form.save() self.assertEqual(spread.debit_account_id, self.account_revenue) self.assertFalse(spread.is_debit_account_deprecated) self.assertEqual(spread.journal_id, self.sales_journal) self.assertEqual(spread.spread_type, "sale") spread_form = Form(spread) spread_form.invoice_type = "in_invoice" spread = spread_form.save() self.assertEqual(spread.credit_account_id, self.account_payable) self.assertFalse(spread.is_credit_account_deprecated) self.assertEqual(spread.journal_id, self.expenses_journal) self.assertEqual(spread.spread_type, "purchase")
def create_picking(cls, partner, picking_type, product, scheduled_date): picking_form = Form( recordp=cls.env["stock.picking"].with_context( default_picking_type_id=picking_type.id), view="stock.view_picking_form", ) picking_form.company_id = cls.env.user.company_id picking_form.partner_id = partner with picking_form.move_ids_without_package.new() as move: move.product_id = product move.product_uom_qty = 10 picking = picking_form.save() # Edit again to set scheduled_date. scheduled_date is readonly in # creation form picking_form = Form(picking) picking_form.scheduled_date = scheduled_date return picking_form.save()
def generate_purchase_order(self, company, partner): """ Generate purchase order and confirm its state """ purchase_order = Form(self.env['purchase.order']) purchase_order.partner_id = partner purchase_order.company_id = company purchase_order.currency_id = company.currency_id purchase_order = purchase_order.save() with Form(purchase_order) as po: with po.order_line.new() as line: line.name = 'Service' line.product_id = self.product_consultant line.price_unit = 450.0 # Confirm Purchase order purchase_order.button_confirm() # Check purchase order state should be purchase. self.assertEqual(purchase_order.state, 'purchase', 'Purchase order should be in purchase state.') return purchase_order
def _generate_draft_sale_order(self, company, partner, user): """ Generate sale order and confirm its state """ sale_order = Form(self.env['sale.order']) sale_order.company_id = company sale_order.warehouse_id = company.warehouse_id sale_order.user_id = user sale_order.pricelist_id = self.env['product.pricelist'].search([('id', '=', 1)]) sale_order.partner_id = partner sale_order.partner_invoice_id = partner sale_order.partner_shipping_id = partner sale_order = sale_order.save() with Form(sale_order) as so: with so.order_line.new() as line: line.name = 'Service' line.product_id = self.product_consultant line.price_unit = 450.0 return sale_order
def test_onchanges_order(self): expected_date = fields.Datetime.now() wh = (self.env["stock.warehouse"].with_context( company_id=self.main_company.id).create({ "name": "Warehouse", "code": "Warehouse", "company_id": self.main_company.id, "partner_id": self.main_company.id, })) new_pick_type = (self.env["stock.picking.type"].with_context( company_id=self.main_company.id).create({ "name": "Stock Request wh", "sequence_id": self.env.ref("stock_request.seq_stock_request_order").id, "code": "stock_request_order", "sequence_code": "SRO", "warehouse_id": wh.id, })) form = Form(self.env["stock.request.order"]) form.company_id = self.main_company form.expected_date = expected_date form.warehouse_id = self.warehouse form.location_id = self.warehouse.lot_stock_id form.save() # Test onchange_warehouse_picking_id form.warehouse_id = wh form.save() self.assertEqual(form.picking_type_id, new_pick_type)
def test_lead_mc_company_form(self): """ Test lead company computation using form view """ crm_lead_form = Form(self.env['crm.lead']) crm_lead_form.name = "Test Lead" # default values: current user, its team and therefore its company self.assertEqual(crm_lead_form.company_id, self.company_2) self.assertEqual(crm_lead_form.user_id, self.user_sales_manager_mc) self.assertEqual(crm_lead_form.team_id, self.team_company2) # remove user, team only crm_lead_form.user_id = self.env['res.users'] self.assertEqual(crm_lead_form.company_id, self.company_2) self.assertEqual(crm_lead_form.user_id, self.env['res.users']) self.assertEqual(crm_lead_form.team_id, self.team_company2) # remove team, user only crm_lead_form.user_id = self.user_sales_manager_mc crm_lead_form.team_id = self.env['crm.team'] self.assertEqual(crm_lead_form.company_id, self.company_2) self.assertEqual(crm_lead_form.user_id, self.user_sales_manager_mc) self.assertEqual(crm_lead_form.team_id, self.env['crm.team']) # remove both: void company to ease assignment crm_lead_form.user_id = self.env['res.users'] self.assertEqual(crm_lead_form.company_id, self.env['res.company']) self.assertEqual(crm_lead_form.user_id, self.env['res.users']) self.assertEqual(crm_lead_form.team_id, self.env['crm.team']) # force company manually crm_lead_form.company_id = self.company_2 lead = crm_lead_form.save() # user_sales_manager cannot read it due to MC rules with self.assertRaises(AccessError): lead.with_user(self.user_sales_manager).read(['name'])