def _interval_dates(self, frequency, company): """ Method used to compute the theoretical date from which account move lines should be fetched @param {string} frequency: a valid value of the selection field on the object (daily, monthly, annually) frequencies are literal (daily means 24 hours and so on) @param {recordset} company: the company for which the closing is done @return {dict} the theoretical date from which account move lines are fetched. date_stop date to which the move lines are fetched, always now() the dates are in their NobleCRM Database string representation """ date_stop = datetime.utcnow() interval_from = None name_interval = '' if frequency == 'daily': interval_from = date_stop - timedelta(days=1) name_interval = _('Daily Closing') elif frequency == 'monthly': month_target = date_stop.month > 1 and date_stop.month - 1 or 12 year_target = month_target < 12 and date_stop.year or date_stop.year - 1 interval_from = date_stop.replace(year=year_target, month=month_target) name_interval = _('Monthly Closing') elif frequency == 'annually': year_target = date_stop.year - 1 interval_from = date_stop.replace(year=year_target) name_interval = _('Annual Closing') return { 'interval_from': FieldDateTime.to_string(interval_from), 'date_stop': FieldDateTime.to_string(date_stop), 'name_interval': name_interval }
def test_event_date_range(self): self.patcher = patch( 'noblecrm.addons.event.models.event.fields.Datetime', wraps=Datetime) self.mock_datetime = self.patcher.start() self.mock_datetime.now.return_value = Datetime.to_string( datetime.datetime(2015, 12, 31, 12, 0)) self.event_0.registration_ids.event_begin_date = datetime.datetime( 2015, 12, 31, 18, 0) self.assertEqual(self.event_0.registration_ids.get_date_range_str(), u'today') self.event_0.registration_ids.event_begin_date = datetime.datetime( 2016, 1, 1, 6, 0) self.assertEqual(self.event_0.registration_ids.get_date_range_str(), u'tomorrow') self.event_0.registration_ids.event_begin_date = datetime.datetime( 2016, 1, 2, 6, 0) self.assertEqual(self.event_0.registration_ids.get_date_range_str(), u'in 2 days') self.mock_datetime.now.return_value = Datetime.to_string( datetime.datetime(2015, 12, 10, 12, 0)) self.event_0.registration_ids.event_begin_date = datetime.datetime( 2016, 1, 25, 6, 0) self.assertEqual(self.event_0.registration_ids.get_date_range_str(), u'next month') self.patcher.stop()
def test_in_date_5(self): """ Receive the same lot at different times, once they're in the same location, the quants are merged and only the earliest incoming date is kept. """ stock_location = self.env.ref('stock.stock_location_stock') product1 = self.env['product.product'].create({ 'name': 'Product A', 'type': 'product', 'tracking': 'lot', }) lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', 'product_id': product1.id, }) in_date1 = datetime.now() self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot1, in_date=in_date1) quant = self.env['stock.quant'].search([ ('product_id', '=', product1.id), ('location_id', '=', stock_location.id), ]) self.assertEqual(len(quant), 1) self.assertEqual(quant.quantity, 1) self.assertEqual(quant.lot_id.id, lot1.id) from noblecrm.fields import Datetime self.assertEqual(quant.in_date, Datetime.to_string(in_date1)) in_date2 = datetime.now() - timedelta(days=5) self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot1, in_date=in_date2) quant = self.env['stock.quant'].search([ ('product_id', '=', product1.id), ('location_id', '=', stock_location.id), ]) self.assertEqual(len(quant), 1) self.assertEqual(quant.quantity, 2) self.assertEqual(quant.lot_id.id, lot1.id) self.assertEqual(quant.in_date, Datetime.to_string(in_date2))
def test_07(self): """After 182 days, exactly half of the budget line""" date = Datetime.to_string(Datetime.from_string('2014-07-02 00:00:00')) self.mock_datetime.now.return_value = date self.assertAlmostEqual(self.line.theoritical_amount, -182)
def test_06(self): """After 50 days""" date = Datetime.to_string(Datetime.from_string('2014-02-20 00:00:00')) self.mock_datetime.now.return_value = date self.assertAlmostEqual(self.line.theoritical_amount, -50)
def test_04(self): """After 48 hours""" date = Datetime.to_string(Datetime.from_string('2014-01-03 00:00:00')) self.mock_datetime.now.return_value = date self.assertAlmostEqual(self.line.theoritical_amount, -2)
def test_01(self): """Start""" date = Datetime.to_string(Datetime.from_string('2014-01-01 00:00:00')) self.mock_datetime.now.return_value = date self.assertAlmostEqual(self.line.theoritical_amount, 0)
def test_10(self): """At last""" date = Datetime.to_string(Datetime.from_string('2014-12-31 00:00:00')) self.mock_datetime.now.return_value = date self.assertAlmostEqual(self.line.theoritical_amount, -364)
def test_09(self): """One day before""" date = Datetime.to_string(Datetime.from_string('2014-12-30 00:00:00')) self.mock_datetime.now.return_value = date self.assertAlmostEqual(self.line.theoritical_amount, -363)
def test_08(self): """After 308 days at noon""" date = Datetime.to_string( Datetime.from_string('2014-11-05 12:00:00')) # remember, remember self.mock_datetime.now.return_value = date self.assertAlmostEqual(self.line.theoritical_amount, -308.5)
def test_basic(self): """ Basic order test: no routing (thus no workorders), no lot """ self.product_1.type = 'product' self.product_2.type = 'product' inventory = self.env['stock.inventory'].create({ 'name': 'Initial inventory', 'filter': 'partial', 'line_ids': [(0, 0, { 'product_id': self.product_1.id, 'product_uom_id': self.product_1.uom_id.id, 'product_qty': 500, 'location_id': self.warehouse_1.lot_stock_id.id }), (0, 0, { 'product_id': self.product_2.id, 'product_uom_id': self.product_2.uom_id.id, 'product_qty': 500, 'location_id': self.warehouse_1.lot_stock_id.id })] }) inventory.action_done() test_date_planned = datetime.now() - timedelta(days=1) test_quantity = 2.0 self.bom_1.routing_id = False man_order = self.env['mrp.production'].sudo(self.user_mrp_user).create( { 'name': 'Stick-0', 'product_id': self.product_4.id, 'product_uom_id': self.product_4.uom_id.id, 'product_qty': test_quantity, 'bom_id': self.bom_1.id, 'date_planned_start': test_date_planned, 'location_src_id': self.location_1.id, 'location_dest_id': self.warehouse_1.wh_output_stock_loc_id.id, }) self.assertEqual(man_order.state, 'confirmed', "Production order should be in confirmed state.") # check production move production_move = man_order.move_finished_ids self.assertEqual(production_move.date, Dt.to_string(test_date_planned)) self.assertEqual(production_move.product_id, self.product_4) self.assertEqual(production_move.product_uom, man_order.product_uom_id) self.assertEqual(production_move.product_qty, man_order.product_qty) self.assertEqual(production_move.location_id, self.product_4.property_stock_production) self.assertEqual(production_move.location_dest_id, man_order.location_dest_id) # check consumption moves for move in man_order.move_raw_ids: self.assertEqual(move.date, Dt.to_string(test_date_planned)) first_move = man_order.move_raw_ids.filtered( lambda move: move.product_id == self.product_2) self.assertEqual( first_move.product_qty, test_quantity / self.bom_1.product_qty * self.product_4.uom_id.factor_inv * 2) first_move = man_order.move_raw_ids.filtered( lambda move: move.product_id == self.product_1) self.assertEqual( first_move.product_qty, test_quantity / self.bom_1.product_qty * self.product_4.uom_id.factor_inv * 4) # waste some material, create a scrap # scrap = self.env['stock.scrap'].with_context( # active_model='mrp.production', active_id=man_order.id # ).create({}) # scrap = self.env['stock.scrap'].create({ # 'production_id': man_order.id, # 'product_id': first_move.product_id.id, # 'product_uom_id': first_move.product_uom.id, # 'scrap_qty': 5.0, # }) # check created scrap # procurements = self.env['procurement.order'].search([('move_dest_id', 'in', man_order.move_raw_ids.ids)]) # print procurements # procurements = self.env['procurement.order'].search([('production_id', '=', man_order.id)]) # print procurements # for proc in self.env['procurement.order'].browse(procurements): # date_planned = self.mrp_production_test1.date_planned # if proc.product_id.type not in ('product', 'consu'): # continue # if proc.product_id.id == order_line.product_id.id: # self.assertEqual(proc.date_planned, date_planned, "Planned date does not correspond") # # procurement state should be `confirmed` at this stage, except if procurement_jit is installed, in which # # case it could already be in `running` or `exception` state (not enough stock) # expected_states = ('confirmed', 'running', 'exception') # self.assertEqual(proc.state in expected_states, 'Procurement state is `%s` for %s, expected one of %s' % (proc.state, proc.product_id.name, expected_states)) # Change production quantity qty_wizard = self.env['change.production.qty'].create({ 'mo_id': man_order.id, 'product_qty': 3.0, }) # qty_wizard.change_prod_qty() # # I check qty after changed in production order. # #self.assertEqual(self.mrp_production_test1.product_qty, 3, "Qty is not changed in order.") # move = self.mrp_production_test1.move_finished_ids[0] # self.assertEqual(move.product_qty, self.mrp_production_test1.product_qty, "Qty is not changed in move line.") # # I run scheduler. # self.env['procurement.order'].run_scheduler() # # The production order is Waiting Goods, will force production which should set consume lines as available # self.mrp_production_test1.button_plan() # # I check that production order in ready state after forcing production. # #self.assertEqual(self.mrp_production_test1.availability, 'assigned', 'Production order availability should be set as available') # produce product produce_wizard = self.env['mrp.product.produce'].sudo( self.user_mrp_user).with_context({ 'active_id': man_order.id, 'active_ids': [man_order.id], }).create({ 'product_qty': 1.0, }) produce_wizard.do_produce() # man_order.button_mark_done() man_order.button_mark_done() self.assertEqual(man_order.state, 'done', "Production order should be in done state.")