def test_computes_auto_fill(self): free_product = self.env['product.product'].create({ 'name': 'Free product', 'list_price': 0.0, }) dummy_product = self.env['product.product'].create({ 'name': 'Dummy product', 'list_price': 0.0, }) # Test pre-computes of lines with order order = self.env['sale.order'].create({ 'partner_id': self.partner_a.id, 'order_line': [ Command.create({ 'display_type': 'line_section', 'name': 'Dummy section', }), Command.create({ 'display_type': 'line_section', 'name': 'Dummy section', }), Command.create({ 'product_id': free_product.id, }), Command.create({ 'product_id': dummy_product.id, }) ] }) # Test pre-computes of lines creation alone # Ensures the creation works fine even if the computes # are triggered after the defaults order = self.env['sale.order'].create({ 'partner_id': self.partner_a.id, }) self.env['sale.order.line'].create([ { 'display_type': 'line_section', 'name': 'Dummy section', 'order_id': order.id, }, { 'display_type': 'line_section', 'name': 'Dummy section', 'order_id': order.id, }, { 'product_id': free_product.id, 'order_id': order.id, }, { 'product_id': dummy_product.id, 'order_id': order.id, } ])
def setUpClass(cls): super().setUpClass() cls.pricelist = cls.env['product.pricelist'].search( [('currency_id', '=', cls.currency.id)], limit=1) if not cls.pricelist: cls.pricelist = cls.env['product.pricelist'].create({ 'name': 'Test Pricelist (%s)' % (cls.currency.name), 'currency_id': cls.currency.id, }) cls.sale_product = cls.env['product.product'].create({ 'sale_ok': True, 'name': "Test Product", }) cls.order = cls.env['sale.order'].create({ 'partner_id': cls.partner.id, 'pricelist_id': cls.pricelist.id, 'order_line': [ Command.create({ 'product_id': cls.sale_product.id, 'product_uom_qty': 5, 'price_unit': 20, }) ], })
def test_so_create_multicompany(self): """Check that only taxes of the right company are applied on the lines.""" # Preparing test Data product_shared = self.env['product.template'].create({ 'name': 'shared product', 'invoice_policy': 'order', 'taxes_id': [(6, False, (self.company_data['default_tax_sale'] + self.company_data_2['default_tax_sale']).ids)], 'property_account_income_id': self.company_data['default_account_revenue'].id, }) so_1 = self.env['sale.order'].with_user(self.company_data['default_user_salesman']).create({ 'partner_id': self.env['res.partner'].create({'name': 'A partner'}).id, 'company_id': self.company_data['company'].id, }) so_1.write({ 'order_line': [Command.create({'product_id': product_shared.product_variant_id.id, 'order_id': so_1.id})], }) self.assertEqual(so_1.order_line.product_uom_qty, 1) self.assertEqual(so_1.order_line.tax_id, self.company_data['default_tax_sale'], 'Only taxes from the right company are put by default') so_1.action_confirm() # i'm not interested in groups/acls, but in the multi-company flow only # the sudo is there for that and does not impact the invoice that gets created # the goal here is to invoice in company 1 (because the order is in company 1) while being # 'mainly' in company 2 (through the context), the invoice should be in company 1 inv=so_1.sudo()\ .with_context(allowed_company_ids=(self.company_data['company'] + self.company_data_2['company']).ids)\ ._create_invoices() self.assertEqual(inv.company_id, self.company_data['company'], 'invoices should be created in the company of the SO, not the main company of the context')
def test_mailing_test_equals_reality(self): """ Check that both test and real emails will format the qweb and inline placeholders correctly in body and subject. """ contact_list = self.env['mailing.list'].create({ 'name': 'Testers', 'contact_ids': [ Command.create({ 'name': 'Mitchell Admin', 'email': '*****@*****.**', }) ], }) mailing = self.env['mailing.mailing'].create({ 'name': 'TestButton', 'subject': 'Subject {{ object.name }} <t t-out="object.name"/>', 'state': 'draft', 'mailing_type': 'mail', 'body_html': '<p>Hello {{ object.name }} <t t-out="object.name"/></p>', 'mailing_model_id': self.env['ir.model']._get('mailing.list').id, 'contact_list_ids': [contact_list.id], }) mailing_test = self.env['mailing.mailing.test'].create({ 'email_to': '*****@*****.**', 'mass_mailing_id': mailing.id, }) with self.mock_mail_gateway(): mailing_test.send_mail_test() expected_subject = 'Subject Mitchell Admin <t t-out="object.name"/>' expected_body = 'Hello {{ object.name }} Mitchell Admin' self.assertSentEmail(self.env.user.partner_id, ['*****@*****.**'], subject=expected_subject, body_content=expected_body) with self.mock_mail_gateway(): # send the mailing mailing.action_launch() self.env.ref('mass_mailing.ir_cron_mass_mailing_queue' ).method_direct_trigger() self.assertSentEmail(self.env.user.partner_id, ['*****@*****.**'], subject=expected_subject, body_content=expected_body)
def test_so_tax_mapping(self): uom = self.env['uom.uom'].search([('name', '=', 'Units')], limit=1) pricelist = self.env['product.pricelist'].search( [('name', '=', 'Public Pricelist')], limit=1) partner = self.env['res.partner'].create(dict(name="George")) tax_include = self.env['account.tax'].create( dict(name="Include tax", amount='21.00', price_include=True, type_tax_use='sale')) tax_exclude = self.env['account.tax'].create( dict(name="Exclude tax", amount='0.00', type_tax_use='sale')) product_tmpl = self.env['product.template'].create( dict(name="Voiture", list_price=121, taxes_id=[(6, 0, [tax_include.id])])) product = product_tmpl.product_variant_id fpos = self.env['account.fiscal.position'].create( dict(name="fiscal position", sequence=1)) self.env['account.fiscal.position.tax'].create({ 'position_id': fpos.id, 'tax_src_id': tax_include.id, 'tax_dest_id': tax_exclude.id, }) sale_order = self.env['sale.order'].create({ 'partner_id': partner.id, 'pricelist_id': pricelist.id, 'fiscal_position_id': fpos.id, 'order_line': [ Command.create({ 'product_id': product.id, 'product_uom': uom.id, }) ] }) # Check the unit price of SO line self.assertEqual(100, sale_order.order_line[0].price_unit, "The included tax must be subtracted to the price")
def test_pricelist_application(self): """ Test different prices are correctly applied based on dates """ support_product = self.env['product.product'].create({ 'name': 'Virtual Home Staging', 'list_price': 100, }) partner = self.env['res.partner'].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 so = self.env['sale.order'].create({ 'partner_id': partner.id, 'date_order': '2017-12-20', 'pricelist_id': christmas_pricelist.id, 'order_line': [Command.create({'product_id': support_product.id})] }) # 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.assertEqual(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 so.date_order = '2017-12-30' so.update_prices() self.assertEqual(so.order_line[0].price_unit, 50, "Second date pricelist rule not applied") self.assertEqual(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')
def create_invoice(cls, **kwargs): return (cls.env['account.move'].with_context( edi_test_mode=True).create({ 'move_type': 'out_invoice', 'partner_id': cls.partner_a.id, 'invoice_date': '2022-03-15', 'date': '2022-03-15', **kwargs, 'invoice_line_ids': [ Command.create({ **line_vals, }) for line_vals in kwargs.get('invoice_line_ids', []) ] }))
def test_make_billable_at_task_rate(self): """ Starting from a non billable project, make it billable at task rate """ Timesheet = self.env['account.analytic.line'] Task = self.env['project.task'] # set a customer on the project self.project_non_billable.write({ 'partner_id': self.partner_2.id, 'timesheet_product_id': self.product_delivery_timesheet3, }) # create a task and 2 timesheets task = Task.with_context( default_project_id=self.project_non_billable.id).create({ 'name': 'first task', 'partner_id': self.project_non_billable.partner_id.id, 'planned_hours': 10, }) timesheet1 = Timesheet.create({ 'name': 'Test Line', 'project_id': task.project_id.id, 'task_id': task.id, 'unit_amount': 3, 'employee_id': self.employee_manager.id, }) timesheet2 = Timesheet.create({ 'name': 'Test Line tde', 'project_id': task.project_id.id, 'task_id': task.id, 'unit_amount': 2, 'employee_id': self.employee_tde.id, }) # Change project to billable at task rate self.project_non_billable.write({ 'allow_billable': True, }) # create wizard wizard = self.env['project.create.sale.order'].with_context( active_id=self.project_non_billable.id, active_model='project.project').create({ 'line_ids': [ Command.create({ 'product_id': self.product_delivery_timesheet3.id, 'price_unit': self.product_delivery_timesheet3.lst_price }), ], }) self.assertEqual( wizard.partner_id, self.project_non_billable.partner_id, "The wizard should have the same partner as the project") self.assertEqual(len(wizard.line_ids), 1, "The wizard should have one line") self.assertEqual(wizard.line_ids.product_id, self.product_delivery_timesheet3, "The wizard should have one line with right product") # create the SO from the project action = wizard.action_create_sale_order() sale_order = self.env['sale.order'].browse(action['res_id']) self.assertEqual( sale_order.partner_id, self.project_non_billable.partner_id, "The customer of the SO should be the same as the project") self.assertEqual(len(sale_order.order_line), 1, "The SO should have 1 line") self.assertEqual( sale_order.order_line.product_id, wizard.line_ids.product_id, "The product of the only SOL should be the selected on the wizard") self.assertEqual(sale_order.order_line.project_id, self.project_non_billable, "SOL should be linked to the project") self.assertTrue( sale_order.order_line.task_id, "The SOL creates a task as they were no task already present in the project (system limitation)" ) self.assertEqual(sale_order.order_line.task_id.project_id, self.project_non_billable, "The created task should be in the project") self.assertEqual( sale_order.order_line.qty_delivered, timesheet1.unit_amount + timesheet2.unit_amount, "The create SOL should have an delivered quantity equals to the sum of tasks'timesheets" ) self.assertEqual( self.project_non_billable.pricing_type, 'fixed_rate', 'The pricing type of the project should be project rate since we linked a SO in the project.' )
def button_create(self): """创建作者方法""" self.authors = [Command.create({ "name": "瑶瑶" })]
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')
def test_duplicate_project_with_subtask_dependencies(self): self.project_goats.allow_task_dependencies = True self.project_goats.allow_subtasks = True parent_task = self.env['project.task'].with_context({ 'mail_create_nolog': True }).create({ 'name': 'Parent Task', 'project_id': self.project_goats.id, 'child_ids': [ Command.create({'name': 'Node 1'}), Command.create({ 'name': 'SuperNode 2', 'child_ids': [Command.create({'name': 'Node 2'})] }), Command.create({'name': 'Node 3'}), ], }) node1 = parent_task.child_ids[0] node2 = parent_task.child_ids[1].child_ids node3 = parent_task.child_ids[2] node1.dependent_ids = node2 node2.dependent_ids = node3 # Test copying the whole Node tree parent_task_copy = parent_task.copy() parent_copy_node1 = parent_task_copy.child_ids[0] parent_copy_node2 = parent_task_copy.child_ids[1].child_ids parent_copy_node3 = parent_task_copy.child_ids[2] # Relation should only be copied between the newly created node self.assertEqual(len(parent_copy_node1.dependent_ids), 1) self.assertEqual(parent_copy_node1.dependent_ids.ids, parent_copy_node2.ids, 'Node1copy - Node2copy relation should be present') self.assertEqual(len(parent_copy_node2.dependent_ids), 1) self.assertEqual(parent_copy_node2.dependent_ids.ids, parent_copy_node3.ids, 'Node2copy - Node3copy relation should be present') # Original Node should not have new relation self.assertEqual(len(node1.dependent_ids), 1) self.assertEqual(node1.dependent_ids.ids, node2.ids, 'Only Node1 - Node2 relation should be present') self.assertEqual(len(node2.dependent_ids), 1) self.assertEqual(node2.dependent_ids.ids, node3.ids, 'Only Node2 - Node3 relation should be present') # Test copying Node inside the chain single_copy_node2 = node2.copy() # Relation should be present between the other original node and the newly copied node self.assertEqual(len(single_copy_node2.depend_on_ids), 1) self.assertEqual(single_copy_node2.depend_on_ids.ids, node1.ids, 'Node1 - Node2copy relation should be present') self.assertEqual(len(single_copy_node2.dependent_ids), 1) self.assertEqual(single_copy_node2.dependent_ids.ids, node3.ids, 'Node2copy - Node3 relation should be present') # Original Node should have new relations self.assertEqual(len(node1.dependent_ids), 2) self.assertEqual(len(node3.depend_on_ids), 2)