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 create_po(self, notice=False, picking_type_in=None): if not picking_type_in: picking_type_in = self.picking_type_in_warehouse po = Form(self.env["purchase.order"]) po.partner_id = self.vendor po.picking_type_id = picking_type_in with po.order_line.new() as po_line: po_line.product_id = self.product_1 po_line.product_qty = self.qty_po_p1 po_line.price_unit = self.price_p1 with po.order_line.new() as po_line: po_line.product_id = self.product_2 po_line.product_qty = self.qty_po_p2 po_line.price_unit = self.price_p2 po = po.save() po.button_confirm() self.picking = po.picking_ids[0] self.picking.write({"notice": notice}) for move_line in self.picking.move_line_ids: if move_line.product_id == self.product_1: move_line.write({"qty_done": self.qty_po_p1}) if move_line.product_id == self.product_2: move_line.write({"qty_done": self.qty_po_p2}) self.picking.button_validate() self.picking.action_done() _logger.info("Receptie facuta") self.po = po return po
def create_po(self, picking_type_in=None): po = Form(self.env["purchase.order"]) po.partner_id = self.vendor with po.order_line.new() as po_line: po_line.product_id = self.product_1 po_line.product_qty = self.qty_po_p1 po_line.price_unit = self.price_p1 with po.order_line.new() as po_line: po_line.product_id = self.product_2 po_line.product_qty = self.qty_po_p2 po_line.price_unit = self.price_p2 po = po.save() po.button_confirm() self.picking = po.picking_ids[0] for move_line in self.picking.move_line_ids: if move_line.product_id == self.product_1: move_line.write({"qty_done": self.qty_po_p1}) if move_line.product_id == self.product_2: move_line.write( {"qty_done": self.qty_po_p2, "location_dest_id": self.location_2} ) self.picking.button_validate() _logger.info("Receptie facuta") self.po = po return po
def test_reminder_2(self): """Set to send reminder tomorrow, check if no reminder can be send. """ po = Form(self.env['purchase.order']) po.partner_id = self.vendor with po.order_line.new() as po_line: po_line.product_id = self.product_consu po_line.product_qty = 1 po_line.price_unit = 100 with po.order_line.new() as po_line: po_line.product_id = self.product_consu2 po_line.product_qty = 10 po_line.price_unit = 200 # set to send reminder tomorrow po.date_planned = fields.Datetime.now() + timedelta(days=2) 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 no reminder send self.assertFalse(messages_send)
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 _create_sale_order(self): order_form = Form(self.env["sale.order"]) order_form.partner_id = self.partner with order_form.order_line.new() as line_form: line_form.product_id = self.product line_form.product_uom_qty = 10 sale = order_form.save() delivery_wizard = Form( self.env["choose.delivery.carrier"].with_context( {"default_order_id": sale.id, "default_carrier_id": self.carrier.id} ) ).save() delivery_wizard.button_confirm() sale.action_confirm() return sale
def test_no_auto_refresh_picking(self): self.env["ir.config_parameter"].sudo().set_param(self.param_name2, "0") self.order.order_line.product_uom_qty = 3 wiz = Form(self.env["choose.delivery.carrier"].with_context({ "default_order_id": self.order.id, "default_carrier_id": self.carrier_1.id, })).save() wiz.button_confirm() self.order.action_confirm() picking = self.order.picking_ids picking.action_assign() picking.move_line_ids[0].qty_done = 2 picking.action_done() line_delivery = self.order.order_line.filtered("is_delivery") self.assertEqual(line_delivery.price_unit, 60)
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>\n' '<p> - 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>\n' '<p> - product_a from 2020-06-06 to %(today)s</p>\n' '<p> - product_b from 2020-06-06 to %(today)s</p>' % {'today': fields.Date.today()}, activity.note, )
def test_report_with_stock_landed_costs(self): self.env.company.anglo_saxon_accounting = True # Create PO with Product A po_form = Form(self.env["purchase.order"]) po_form.partner_id = self.vendor with po_form.order_line.new() as po_line: po_line.product_id = self.product_1 po_line.product_qty = 1 po_line.price_unit = 70.0 po_form = po_form.save() po_form.button_confirm() # Receive the goods receipt = po_form.picking_ids[0] receipt.move_line_ids.qty_done = 1 receipt.button_validate() # Check SVL svl = self.env["stock.valuation.layer"].search( [("stock_move_id", "=", receipt.move_lines.id)] ) self.assertAlmostEqual(svl.value, 70) # copy svl dand modify the quantity svl2 = svl.copy() svl2.quantity = 0 svl2.unit_cost = 0 svl2.value = 20 wizard = Form(self.env["stock.storage.sheet"]) wizard.location_id = self.location wizard = wizard.save() wizard.button_show_sheet_pdf() line = self.env["stock.storage.sheet.line"].search( [("report_id", "=", wizard.id), ("product_id", "=", self.product_1.id)] ) self.assertEqual(sum(line.mapped("amount_initial")), 0) self.assertEqual(sum(line.mapped("quantity_initial")), 0) self.assertEqual(sum(line.mapped("amount_in")), 90) self.assertEqual(sum(line.mapped("quantity_in")), 1) self.assertEqual(sum(line.mapped("amount_out")), 0) self.assertEqual(sum(line.mapped("quantity_out")), 0) self.assertEqual(sum(line.mapped("amount_final")), 90) self.assertEqual(sum(line.mapped("quantity_final")), 1)
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 test_auto_refresh_so(self): self.assertFalse(self.order.order_line.filtered("is_delivery")) self.env["ir.config_parameter"].sudo().set_param(self.param_name1, 1) self.order.write({ "order_line": [(1, self.order.order_line.id, { "product_uom_qty": 3 })] }) line_delivery = self.order.order_line.filtered("is_delivery") self.assertEqual(line_delivery.price_unit, 60) line2 = self.order.order_line.new({ "order_id": self.order.id, "product_id": self.product.id, "product_uom_qty": 2, }) _execute_onchanges(line2, "product_id") vals = line2._convert_to_write(line2._cache) del vals["order_id"] self.order.write({"order_line": [(0, 0, vals)]}) line_delivery = self.order.order_line.filtered("is_delivery") self.assertEqual(line_delivery.price_unit, 95) # Test saving the discount line_delivery.discount = 10 self.order.carrier_id = self.carrier_2 line_delivery = self.order.order_line.filtered("is_delivery") self.assertEqual(line_delivery.discount, 10) # Test change the carrier_id using the wizard wiz = Form(self.env["choose.delivery.carrier"].with_context({ "default_order_id": self.order.id, "default_carrier_id": self.carrier_1.id, })).save() wiz.button_confirm() self.assertEqual(self.order.carrier_id, self.carrier_1) line_delivery = self.order.order_line.filtered("is_delivery") self.assertEqual(line_delivery.name, "Test carrier 1")
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.price_unit = 10 po_line.product_qty = 10 po_line.taxes_id.clear() rfq = rfq.save() rfq.button_confirm() # Process the receipt receipt = rfq.picking_ids wiz = receipt.button_validate() wiz = self.env['stock.immediate.transfer'].browse( wiz['res_id']).with_context(wiz['context']).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_view_invoice() vb = Form(self.env['account.move'].with_context(action['context'])) vb = vb.save() vb.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_type='in_invoice')) lcvb.partner_id = self.vendor2 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.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': '*****@*****.**' }) 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.subcontracting_resupply_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.subcontracting_resupply_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.subcontracting_resupply_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)
def test_date_planned_1(self): """Set a date planned on a PO, see that it is set on the PO lines. Try to edit the date planned of the PO line, see that it is not possible. Unset the date planned on the PO and edit the date planned on the PO lines. Validate the PO and see that it isn't possible to set the date planned on the PO nor on the PO lines. """ po = Form(self.env['purchase.order']) po.partner_id = self.vendor with po.order_line.new() as po_line: po_line.product_id = self.product_consu po_line.product_qty = 1 po_line.price_unit = 100 with po.order_line.new() as po_line: po_line.product_id = self.product_consu2 po_line.product_qty = 10 po_line.price_unit = 200 po = po.save() # Check there is no date planned on the PO and the same date planned on both PO lines. self.assertEqual(po.date_planned, False) self.assertNotEqual(po.order_line[0].date_planned, False) self.assertAlmostEqual(po.order_line[0].date_planned, po.order_line[1].date_planned, delta=timedelta(seconds=10)) orig_date_planned = po.order_line[0].date_planned # Set a date planned on a PO, see that it is set on the PO lines. new_date_planned = orig_date_planned + timedelta(hours=1) po.date_planned = new_date_planned self.assertAlmostEqual(po.order_line[0].date_planned, new_date_planned, delta=timedelta(seconds=10)) self.assertAlmostEqual(po.order_line[1].date_planned, new_date_planned, delta=timedelta(seconds=10)) # Try to edit the date planned of the PO line, see that it is not possible po = Form(po) with self.assertRaises(AssertionError): po.order_line.edit(0).date_planned = orig_date_planned with self.assertRaises(AssertionError): po.order_line.edit(1).date_planned = orig_date_planned po = po.save() self.assertAlmostEqual(po.order_line[0].date_planned, new_date_planned, delta=timedelta(seconds=10)) self.assertAlmostEqual(po.order_line[1].date_planned, new_date_planned, delta=timedelta(seconds=10)) # Unset the date planned on the PO and edit the date planned on the PO line. po = Form(po) po.date_planned = False with po.order_line.edit(0) as po_line: po_line.date_planned = orig_date_planned with po.order_line.edit(1) as po_line: po_line.date_planned = orig_date_planned po = po.save() self.assertAlmostEqual(po.order_line[0].date_planned, orig_date_planned, delta=timedelta(seconds=10)) self.assertAlmostEqual(po.order_line[1].date_planned, orig_date_planned, delta=timedelta(seconds=10)) # Validate the PO and see that it isn't possible to set the date planned on the PO # nor on the PO lines. po.button_confirm() po.button_done() po = Form(po) with self.assertRaises(AssertionError): po.date_planned = new_date_planned with self.assertRaises(AssertionError): with po.order_line.edit(0) as po_line: po_line.date_planned = orig_date_planned with self.assertRaises(AssertionError): with po.order_line.edit(1) as po_line: po_line.date_planned = orig_date_planned po.save()