def test_reminder_1(self): """Set to send reminder today, check if a reminder can be send to the partner. """ po = Form(self.env['purchase.order']) po.partner_id = self.partner_a with po.order_line.new() as po_line: po_line.product_id = self.product_a po_line.product_qty = 1 po_line.price_unit = 100 with po.order_line.new() as po_line: po_line.product_id = self.product_b po_line.product_qty = 10 po_line.price_unit = 200 # set to send reminder today po.date_planned = fields.Datetime.now() + timedelta(days=1) po.receipt_reminder_email = True po.reminder_date_before_receipt = 1 po = po.save() po.button_confirm() # check vendor is a message recipient self.assertTrue(po.partner_id in po.message_partner_ids) old_messages = po.message_ids po._send_reminder_mail() messages_send = po.message_ids - old_messages # check reminder send self.assertTrue(messages_send) self.assertTrue(po.partner_id in messages_send.mapped('partner_ids')) # check confirm button po.confirm_reminder_mail() self.assertTrue(po.mail_reminder_confirmed)
def test_vendor_bill_flow_anglo_saxon_2(self): """In anglo saxon accounting, receive 10@10 and invoice with the addition of 1@50 as a landed costs and create a linked landed costs record. """ self.env.company.anglo_saxon_accounting = True # Create an RFQ for self.product1, 10@10 rfq = Form(self.env['purchase.order']) rfq.partner_id = self.vendor1 with rfq.order_line.new() as po_line: po_line.product_id = self.product1 po_line.product_qty = 10 po_line.price_unit = 10 po_line.taxes_id.clear() rfq = rfq.save() rfq.button_confirm() # Process the receipt receipt = rfq.picking_ids wiz = receipt.button_validate() wiz = Form(self.env['stock.immediate.transfer'].with_context(wiz['context'])).save() wiz.process() self.assertEqual(rfq.order_line.qty_received, 10) input_aml = self._get_stock_input_move_lines()[-1] self.assertEqual(input_aml.debit, 0) self.assertEqual(input_aml.credit, 100) valuation_aml = self._get_stock_valuation_move_lines()[-1] self.assertEqual(valuation_aml.debit, 100) self.assertEqual(valuation_aml.credit, 0) # Create a vendor bill for the RFQ and add to it the landed cost vb = Form(self.env['account.move'].with_context(default_move_type='in_invoice')) vb.partner_id = self.vendor1 vb.invoice_date = vb.date with vb.invoice_line_ids.new() as inv_line: inv_line.product_id = self.productlc1 inv_line.price_unit = 50 inv_line.is_landed_costs_line = True vb = vb.save() vb.action_post() action = vb.button_create_landed_costs() lc = Form(self.env[action['res_model']].browse(action['res_id'])) lc.picking_ids.add(receipt) lc = lc.save() lc.button_validate() # Check reconciliation of input aml of lc lc_input_aml = lc.account_move_id.line_ids.filtered(lambda aml: aml.account_id == self.company_data['default_account_stock_in']) self.assertTrue(len(lc_input_aml.full_reconcile_id), 1)
def test_update_date_planned(self): po = Form(self.env['purchase.order']) po.partner_id = self.partner_a with po.order_line.new() as po_line: po_line.product_id = self.product_a po_line.product_qty = 1 po_line.price_unit = 100 po_line.date_planned = '2020-06-06 00:00:00' with po.order_line.new() as po_line: po_line.product_id = self.product_b po_line.product_qty = 10 po_line.price_unit = 200 po_line.date_planned = '2020-06-06 00:00:00' po = po.save() po.button_confirm() # update first line po._update_date_planned_for_lines([(po.order_line[0], fields.Datetime.today())]) self.assertEqual(po.order_line[0].date_planned, fields.Datetime.today()) activity = self.env['mail.activity'].search([ ('summary', '=', 'Date Updated'), ('res_model_id', '=', 'purchase.order'), ('res_id', '=', po.id), ]) self.assertTrue(activity) self.assertIn( '<p> partner_a modified receipt dates for the following products:</p><p> \xa0 - product_a from 2020-06-06 to %s </p>' % fields.Date.today(), activity.note, ) # update second line po._update_date_planned_for_lines([(po.order_line[1], fields.Datetime.today())]) self.assertEqual(po.order_line[1].date_planned, fields.Datetime.today()) self.assertIn( '<p> partner_a modified receipt dates for the following products:</p><p> \xa0 - product_a from 2020-06-06 to %s </p><p> \xa0 - product_b from 2020-06-06 to %s </p>' % (fields.Date.today(), fields.Date.today()), activity.note, )
def test_vendor_bill_flow_continental_1(self): """In continental accounting, receive 10@10 and invoice. Then invoice 1@50 as a landed costs and create a linked landed costs record. """ self.env.company.anglo_saxon_accounting = False # Create an RFQ for self.product1, 10@10 rfq = Form(self.env['purchase.order']) rfq.partner_id = self.vendor1 with rfq.order_line.new() as po_line: po_line.product_id = self.product1 po_line.product_qty = 10 po_line.price_unit = 10 po_line.taxes_id.clear() rfq = rfq.save() rfq.button_confirm() # Process the receipt receipt = rfq.picking_ids wiz = receipt.button_validate() wiz = Form(self.env['stock.immediate.transfer'].with_context(wiz['context'])).save().process() self.assertEqual(rfq.order_line.qty_received, 10) input_aml = self._get_stock_input_move_lines()[-1] self.assertEqual(input_aml.debit, 0) self.assertEqual(input_aml.credit, 100) valuation_aml = self._get_stock_valuation_move_lines()[-1] self.assertEqual(valuation_aml.debit, 100) self.assertEqual(valuation_aml.credit, 0) # Create a vebdor bill for the RFQ action = rfq.action_create_invoice() vb = self.env['account.move'].browse(action['res_id']) vb.invoice_date = vb.date vb.action_post() expense_aml = self._get_expense_move_lines()[-1] self.assertEqual(expense_aml.debit, 100) self.assertEqual(expense_aml.credit, 0) payable_aml = self._get_payable_move_lines()[-1] self.assertEqual(payable_aml.debit, 0) self.assertEqual(payable_aml.credit, 100) # Create a vendor bill for a landed cost product, post it and validate a landed cost # linked to this vendor bill. LC; 1@50 lcvb = Form(self.env['account.move'].with_context(default_move_type='in_invoice')) lcvb.partner_id = self.vendor2 lcvb.invoice_date = lcvb.date with lcvb.invoice_line_ids.new() as inv_line: inv_line.product_id = self.productlc1 inv_line.price_unit = 50 inv_line.is_landed_costs_line = True with lcvb.invoice_line_ids.edit(0) as inv_line: inv_line.tax_ids.clear() lcvb = lcvb.save() lcvb.action_post() expense_aml = self._get_expense_move_lines()[-1] self.assertEqual(expense_aml.debit, 50) self.assertEqual(expense_aml.credit, 0) payable_aml = self._get_payable_move_lines()[-1] self.assertEqual(payable_aml.debit, 0) self.assertEqual(payable_aml.credit, 50) action = lcvb.button_create_landed_costs() lc = Form(self.env[action['res_model']].browse(action['res_id'])) lc.picking_ids.add(receipt) lc = lc.save() lc.button_validate() self.assertEqual(lc.cost_lines.price_unit, 50) self.assertEqual(lc.cost_lines.product_id, self.productlc1) input_aml = self._get_stock_input_move_lines()[-1] self.assertEqual(input_aml.debit, 0) self.assertEqual(input_aml.credit, 50) valuation_aml = self._get_stock_valuation_move_lines()[-1] self.assertEqual(valuation_aml.debit, 50) self.assertEqual(valuation_aml.credit, 0) self.assertEqual(self.product1.quantity_svl, 10) self.assertEqual(self.product1.value_svl, 150)
def test_mrp_subcontracting_purchase_2(self): """Let's consider a subcontracted BOM with 1 component. Tick "Resupply Subcontractor on Order" on the component and set a supplier on it. Purchase 1 BOM to the subcontractor. Confirm the purchase and change the purchased quantity to 2. Check that 2 components are delivered to the subcontractor """ # Tick "resupply subconractor on order on component" self.bom.bom_line_ids = [(5, 0, 0)] self.bom.bom_line_ids = [(0, 0, { 'product_id': self.comp1.id, 'product_qty': 1 })] resupply_sub_on_order_route = self.env['stock.location.route'].search([ ('name', '=', 'Resupply Subcontractor on Order') ]) (self.comp1).write( {'route_ids': [(4, resupply_sub_on_order_route.id, None)]}) # Create a supplier and set it to component vendor = self.env['res.partner'].create({ 'name': 'AAA', 'email': '*****@*****.**' }) supplier_info1 = self.env['product.supplierinfo'].create({ 'name': vendor.id, 'price': 50, }) self.comp1.write({ 'seller_ids': [(0, 0, { 'name': vendor.id, 'product_code': 'COMP1' })] }) # Purchase 1 BOM to the subcontractor po = Form(self.env['purchase.order']) po.partner_id = self.subcontractor_partner1 with po.order_line.new() as po_line: po_line.product_id = self.finished po_line.product_qty = 1 po_line.price_unit = 100 po = po.save() # Confirm the purchase po.button_confirm() # Check one delivery order with the component has been created for the subcontractor mo = self.env['mrp.production'].search([('bom_id', '=', self.bom.id)]) self.assertEqual(mo.state, 'confirmed') # Check that 1 delivery with 1 component for the subcontractor has been created picking_delivery = mo.picking_ids wh = picking_delivery.picking_type_id.warehouse_id origin = picking_delivery.origin self.assertEqual(len(picking_delivery), 1) self.assertEqual(len(picking_delivery.move_ids_without_package), 1) self.assertEqual(picking_delivery.picking_type_id, wh.out_type_id) self.assertEqual(picking_delivery.partner_id, self.subcontractor_partner1) # Change the purchased quantity to 2 po.order_line.write({'product_qty': 2}) # Check that two deliveries with 1 component for the subcontractor have been created picking_deliveries = self.env['stock.picking'].search([('origin', '=', origin)]) self.assertEqual(len(picking_deliveries), 2) self.assertEqual(picking_deliveries[0].picking_type_id, wh.out_type_id) self.assertEqual(picking_deliveries[0].partner_id, self.subcontractor_partner1) self.assertTrue(picking_deliveries[0].state != 'cancel') move1 = picking_deliveries[0].move_ids_without_package self.assertEqual(picking_deliveries[1].picking_type_id, wh.out_type_id) self.assertEqual(picking_deliveries[1].partner_id, self.subcontractor_partner1) self.assertTrue(picking_deliveries[1].state != 'cancel') move2 = picking_deliveries[1].move_ids_without_package self.assertEqual(move1.product_id, self.comp1) self.assertEqual(move1.product_uom_qty, 1) self.assertEqual(move2.product_id, self.comp1) self.assertEqual(move2.product_uom_qty, 1)