diff --git a/addons/account/account.py b/addons/account/account.py index df623f32174..21a5ce992d7 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1416,14 +1416,17 @@ class account_move(osv.osv): l[2]['period_id'] = default_period context['period_id'] = default_period - if 'line_id' in vals: + if vals.get('line_id', False): c = context.copy() c['novalidate'] = True c['period_id'] = vals['period_id'] if 'period_id' in vals else self._get_period(cr, uid, context) c['journal_id'] = vals['journal_id'] if 'date' in vals: c['date'] = vals['date'] result = super(account_move, self).create(cr, uid, vals, c) - self.validate(cr, uid, [result], context) + tmp = self.validate(cr, uid, [result], context) + journal = self.pool.get('account.journal').browse(cr, uid, vals['journal_id'], context) + if journal.entry_posted and tmp: + self.button_validate(cr,uid, [result], context) else: result = super(account_move, self).create(cr, uid, vals, context) return result diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index d56fe27759c..1b7bd658faf 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -349,6 +349,7 @@ + diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 7f5fa9707c1..0fc9d9e2227 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -1283,7 +1283,7 @@ class account_move_line(osv.osv): self.create(cr, uid, data, context) del vals['account_tax_id'] - if check and ((not context.get('no_store_function')) or journal.entry_posted): + if check and not context.get('novalidate') and ((not context.get('no_store_function')) or journal.entry_posted): tmp = move_obj.validate(cr, uid, [vals['move_id']], context) if journal.entry_posted and tmp: move_obj.button_validate(cr,uid, [vals['move_id']], context) diff --git a/addons/account/wizard/account_report_partner_ledger_view.xml b/addons/account/wizard/account_report_partner_ledger_view.xml index 34c5d55e4c1..61b57f87d7e 100644 --- a/addons/account/wizard/account_report_partner_ledger_view.xml +++ b/addons/account/wizard/account_report_partner_ledger_view.xml @@ -15,7 +15,7 @@ - + diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py index d4cd1e083b4..6194324e183 100644 --- a/addons/base_calendar/base_calendar.py +++ b/addons/base_calendar/base_calendar.py @@ -1208,20 +1208,44 @@ rule or repeating pattern of time to exclude from the recurring rule."), new_rrule_str = ';'.join(new_rrule_str) rdates = get_recurrent_dates(str(new_rrule_str), exdate, event_date, data['exrule']) for r_date in rdates: - ok = True + # fix domain evaluation + # step 1: check date and replace expression by True or False, replace other expressions by True + # step 2: evaluation of & and | + # check if there are one False + pile = [] for arg in domain: - if arg[0] in ('date', 'date_deadline'): - if (arg[1]=='='): - ok = ok and r_date.strftime('%Y-%m-%d')==arg[2] - if (arg[1]=='>'): - ok = ok and r_date.strftime('%Y-%m-%d')>arg[2] - if (arg[1]=='<'): - ok = ok and r_date.strftime('%Y-%m-%d')='): - ok = ok and r_date.strftime('%Y-%m-%d')>=arg[2] - if (arg[1]=='<='): - ok = ok and r_date.strftime('%Y-%m-%d')<=arg[2] - if not ok: + if str(arg[0]) in (str('date'), str('date_deadline')): + if (arg[1] == '='): + ok = r_date.strftime('%Y-%m-%d')==arg[2] + if (arg[1] == '>'): + ok = r_date.strftime('%Y-%m-%d')>arg[2] + if (arg[1] == '<'): + ok = r_date.strftime('%Y-%m-%d')='): + ok = r_date.strftime('%Y-%m-%d')>=arg[2] + if (arg[1] == '<='): + ok = r_date.strftime('%Y-%m-%d')<=arg[2] + pile.append(ok) + elif str(arg) == str('&') or str(arg) == str('|'): + pile.append(arg) + else: + pile.append(True) + pile.reverse() + new_pile = [] + for item in pile: + if not isinstance(item, basestring): + res = item + elif str(item) == str('&'): + first = new_pile.pop() + second = new_pile.pop() + res = first and second + elif str(item) == str('|'): + first = new_pile.pop() + second = new_pile.pop() + res = first or second + new_pile.append(res) + + if [True for item in new_pile if not item]: continue idval = real_id2base_calendar_id(data['id'], r_date.strftime("%Y-%m-%d %H:%M:%S")) result.append(idval) @@ -1346,18 +1370,17 @@ rule or repeating pattern of time to exclude from the recurring rule."), for arg in args: new_arg = arg - if arg[0] in ('date', unicode('date'), 'date_deadline', unicode('date_deadline')): + if arg[0] in ('date_deadline', unicode('date_deadline')): if context.get('virtual_id', True): - new_args += ['|','&',('recurrency','=',1),('recurrent_id_date', arg[1], arg[2])] + new_args += ['|','&',('recurrency','=',1),('end_date', arg[1], arg[2])] elif arg[0] == "id": new_id = get_real_ids(arg[2]) new_arg = (arg[0], arg[1], new_id) new_args.append(new_arg) - #offset, limit and count must be treated separately as we may need to deal with virtual ids res = super(calendar_event, self).search(cr, uid, new_args, offset=0, limit=0, order=order, context=context, count=False) if context.get('virtual_id', True): - res = self.get_recurrent_ids(cr, uid, res, new_args, limit, context=context) + res = self.get_recurrent_ids(cr, uid, res, args, limit, context=context) if count: return len(res) elif limit: @@ -1436,6 +1459,14 @@ rule or repeating pattern of time to exclude from the recurring rule."), vals['vtimezone'] = vals['vtimezone'][40:] res = super(calendar_event, self).write(cr, uid, ids, vals, context=context) + + # set end_date for calendar searching + if vals.get('recurrency', True) and vals.get('end_type', 'count') in ('count', unicode('count')) and \ + (vals.get('rrule_type') or vals.get('count') or vals.get('date') or vals.get('date_deadline')): + for data in self.read(cr, uid, ids, ['date', 'date_deadline', 'recurrency', 'rrule_type', 'count', 'end_type'], context=context): + end_date = self._set_recurrency_end_date(data, context=context) + super(calendar_event, self).write(cr, uid, [data['id']], {'end_date': end_date}, context=context) + if vals.get('partner_ids', False): self.create_attendees(cr, uid, ids, context) @@ -1554,6 +1585,21 @@ rule or repeating pattern of time to exclude from the recurring rule."), self.unlink_events(cr, uid, ids, context=context) return res + def _set_recurrency_end_date(self, data, context=None): + end_date = data.get('end_date') + if data.get('recurrency') and data.get('end_type') in ('count', unicode('count')): + data_date_deadline = datetime.strptime(data.get('date_deadline'), '%Y-%m-%d %H:%M:%S') + if data.get('rrule_type') in ('daily', unicode('count')): + rel_date = relativedelta(days=data.get('count')+1) + elif data.get('rrule_type') in ('weekly', unicode('weekly')): + rel_date = relativedelta(days=(data.get('count')+1)*7) + elif data.get('rrule_type') in ('monthly', unicode('monthly')): + rel_date = relativedelta(months=data.get('count')+1) + elif data.get('rrule_type') in ('yearly', unicode('yearly')): + rel_date = relativedelta(years=data.get('count')+1) + end_date = data_date_deadline + rel_date + return end_date + def create(self, cr, uid, vals, context=None): if context is None: context = {} @@ -1561,7 +1607,9 @@ rule or repeating pattern of time to exclude from the recurring rule."), if vals.get('vtimezone', '') and vals.get('vtimezone', '').startswith('/freeassociation.sourceforge.net/tzfile/'): vals['vtimezone'] = vals['vtimezone'][40:] + vals['end_date'] = self._set_recurrency_end_date(vals, context=context) res = super(calendar_event, self).create(cr, uid, vals, context) + alarm_obj = self.pool.get('res.alarm') alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date', context=context) self.create_attendees(cr, uid, [res], context) diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index 70f94a4f57e..9226787e908 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -458,7 +458,7 @@ class hr_timesheet_sheet_sheet_day(osv.osv): THEN (SUM(total_attendance) + CASE WHEN current_date <> name THEN 1440 - ELSE (EXTRACT(hour FROM current_time) * 60) + EXTRACT(minute FROM current_time) + ELSE (EXTRACT(hour FROM current_time AT TIME ZONE 'UTC') * 60) + EXTRACT(minute FROM current_time AT TIME ZONE 'UTC') END ) ELSE SUM(total_attendance) diff --git a/addons/mrp/__openerp__.py b/addons/mrp/__openerp__.py index 5f5ded337a7..99afd01707a 100644 --- a/addons/mrp/__openerp__.py +++ b/addons/mrp/__openerp__.py @@ -77,6 +77,7 @@ Dashboard / Reports for MRP will include: #TODO: This yml tests are needed to be completely reviewed again because the product wood panel is removed in product demo as it does not suit for new demo context of computer and consultant company # so the ymls are too complex to change at this stage 'test': [ + 'test/bom_with_service_type_product.yml', 'test/mrp_users.yml', 'test/order_demo.yml', 'test/order_process.yml', diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index e4efc9a4779..475bb065c92 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -601,12 +601,12 @@ class mrp_production(osv.osv): """ self.write(cr, uid, ids, {'state': 'picking_except'}) return True - - def action_compute(self, cr, uid, ids, properties=None, context=None): - """ Computes bills of material of a product. - @param properties: List containing dictionaries of properties. - @return: No. of products. + + def _action_compute_lines(self, cr, uid, ids, properties=None, context=None): + """ Compute product_lines and workcenter_lines from BoM structure + @return: product_lines """ + if properties is None: properties = [] results = [] @@ -614,13 +614,15 @@ class mrp_production(osv.osv): uom_obj = self.pool.get('product.uom') prod_line_obj = self.pool.get('mrp.production.product.line') workcenter_line_obj = self.pool.get('mrp.production.workcenter.line') - for production in self.browse(cr, uid, ids): - - p_ids = prod_line_obj.search(cr, SUPERUSER_ID, [('production_id', '=', production.id)], context=context) - prod_line_obj.unlink(cr, SUPERUSER_ID, p_ids, context=context) - w_ids = workcenter_line_obj.search(cr, SUPERUSER_ID, [('production_id', '=', production.id)], context=context) - workcenter_line_obj.unlink(cr, SUPERUSER_ID, w_ids, context=context) + for production in self.browse(cr, uid, ids, context=context): + #unlink product_lines + prod_line_obj.unlink(cr, SUPERUSER_ID, [line.id for line in production.product_lines], context=context) + + #unlink workcenter_lines + workcenter_line_obj.unlink(cr, SUPERUSER_ID, [line.id for line in production.workcenter_lines], context=context) + + # search BoM structure and route bom_point = production.bom_id bom_id = production.bom_id.id if not bom_point: @@ -629,20 +631,33 @@ class mrp_production(osv.osv): bom_point = bom_obj.browse(cr, uid, bom_id) routing_id = bom_point.routing_id.id or False self.write(cr, uid, [production.id], {'bom_id': bom_id, 'routing_id': routing_id}) - + if not bom_id: raise osv.except_osv(_('Error!'), _("Cannot find a bill of material for this product.")) + + # get components and workcenter_lines from BoM structure factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_point.product_uom.id) res = bom_obj._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, properties, routing_id=production.routing_id.id) - results = res[0] - results2 = res[1] + results = res[0] # product_lines + results2 = res[1] # workcenter_lines + + # reset product_lines in production order for line in results: line['production_id'] = production.id prod_line_obj.create(cr, uid, line) + + #reset workcenter_lines in production order for line in results2: line['production_id'] = production.id workcenter_line_obj.create(cr, uid, line) - return len(results) + return results + + def action_compute(self, cr, uid, ids, properties=None, context=None): + """ Computes bills of material of a product. + @param properties: List containing dictionaries of properties. + @return: No. of products. + """ + return len(self._action_compute_lines(cr, uid, ids, properties=properties, context=context)) def action_cancel(self, cr, uid, ids, context=None): """ Cancels the production order and related stock moves. @@ -669,8 +684,12 @@ class mrp_production(osv.osv): move_obj = self.pool.get('stock.move') self.write(cr, uid, ids, {'state': 'ready'}) - for (production_id,name) in self.name_get(cr, uid, ids): - production = self.browse(cr, uid, production_id) + for production in self.browse(cr, uid, ids, context=context): + if not production.move_created_ids: + produce_move_id = self._make_production_produce_line(cr, uid, production, context=context) + for scheduled in production.product_lines: + self._make_production_line_procurement(cr, uid, scheduled, False, context=context) + if production.move_prod_id and production.move_prod_id.location_id.id != production.location_dest_id.id: move_obj.write(cr, uid, [production.move_prod_id.id], {'location_id': production.location_dest_id.id}) @@ -722,6 +741,10 @@ class mrp_production(osv.osv): stock_mov_obj = self.pool.get('stock.move') production = self.browse(cr, uid, production_id, context=context) + if not production.move_lines and production.state == 'ready': + # trigger workflow if not products to consume (eg: services) + self.signal_button_produce(cr, uid, [production_id]) + produced_qty = 0 for produced_product in production.move_created_ids2: if (produced_product.scrapped) or (produced_product.product_id.id != production.product_id.id): @@ -784,9 +807,9 @@ class mrp_production(osv.osv): subproduct_factor = self._get_subproduct_factor(cr, uid, production.id, produce_product.id, context=context) rest_qty = (subproduct_factor * production.product_qty) - produced_qty - if rest_qty < production_qty: + if rest_qty < (subproduct_factor * production_qty): prod_name = produce_product.product_id.name_get()[0][1] - raise osv.except_osv(_('Warning!'), _('You are going to produce total %s quantities of "%s".\nBut you can only produce up to total %s quantities.') % (production_qty, prod_name, rest_qty)) + raise osv.except_osv(_('Warning!'), _('You are going to produce total %s quantities of "%s".\nBut you can only produce up to total %s quantities.') % ((subproduct_factor * production_qty), prod_name, rest_qty)) if rest_qty > 0 : stock_mov_obj.action_consume(cr, uid, [produce_product.id], (subproduct_factor * production_qty), context=context) @@ -861,13 +884,19 @@ class mrp_production(osv.osv): """ res = True for production in self.browse(cr, uid, ids): - if not production.product_lines: - if not self.action_compute(cr, uid, [production.id]): - res = False + boms = self._action_compute_lines(cr, uid, [production.id]) + res = False + for bom in boms: + product = self.pool.get('product.product').browse(cr, uid, bom['product_id']) + if product.type in ('product', 'consu'): + res = True return res def _get_auto_picking(self, cr, uid, production): return True + + def _hook_create_post_procurement(self, cr, uid, production, procurement_id, context=None): + return True def _make_production_line_procurement(self, cr, uid, production_line, shipment_move_id, context=None): procurement_order = self.pool.get('procurement.order') @@ -1015,11 +1044,13 @@ class mrp_production(osv.osv): for line in production.product_lines: consume_move_id = self._make_production_consume_line(cr, uid, line, produce_move_id, source_location_id=source_location_id, context=context) - shipment_move_id = self._make_production_internal_shipment_line(cr, uid, line, shipment_id, consume_move_id,\ + if shipment_id: + shipment_move_id = self._make_production_internal_shipment_line(cr, uid, line, shipment_id, consume_move_id,\ destination_location_id=source_location_id, context=context) - self._make_production_line_procurement(cr, uid, line, shipment_move_id, context=context) + self._make_production_line_procurement(cr, uid, line, shipment_move_id, context=context) - self.pool.get('stock.picking').signal_button_confirm(cr, uid, [shipment_id]) + if shipment_id: + self.pool.get('stock.picking').signal_button_confirm(cr, uid, [shipment_id]) production.write({'state':'confirmed'}, context=context) return shipment_id diff --git a/addons/mrp/test/bom_with_service_type_product.yml b/addons/mrp/test/bom_with_service_type_product.yml new file mode 100644 index 00000000000..dc434cabf73 --- /dev/null +++ b/addons/mrp/test/bom_with_service_type_product.yml @@ -0,0 +1,134 @@ +- + I create Bill of Materials with one service type product and one consumable product. +- + !record {model: mrp.bom, id: mrp_bom_test1}: + company_id: base.main_company + name: PC Assemble SC234 + product_id: product.product_product_3 + product_qty: 1.0 + type: normal + bom_lines: + - company_id: base.main_company + name: On Site Assistance + product_id: product.product_product_2 + product_qty: 1.0 + - company_id: base.main_company + name: GrapWorks Software + product_id: product.product_product_44 + product_qty: 1.0 +- + I make the production order using BoM having one service type product and one consumable product. +- + !record {model: mrp.production, id: mrp_production_servicetype_mo1}: + product_id: product.product_product_5 + product_qty: 1.0 + bom_id: mrp_bom_test1 + date_planned: !eval time.strftime('%Y-%m-%d %H:%M:%S') +- + I compute the data of production order. +- + !python {model: mrp.production}: | + self.action_compute(cr, uid, [ref("mrp_production_servicetype_mo1")], {"lang": "en_US", "tz": False, "search_default_Current": 1, + "active_model": "ir.ui.menu", "active_ids": [ref("mrp.menu_mrp_production_action")], + "active_id": ref("mrp.menu_mrp_production_action"), }) +- + I confirm the production order. +- + !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_servicetype_mo1} +- + I confirm the Consume Products. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_servicetype_mo1")) + assert order.state == 'confirmed', "Production order should be confirmed." + for move_line in order.move_lines: + move_line.action_consume(move_line.product_qty) +- + I processed the Product Entirely. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_servicetype_mo1")) + assert order.state == 'in_production', 'Production order should be in production State.' + for move_created in order.move_created_ids: + move_created.action_done() +- + I produce product. +- + !python {model: mrp.product.produce}: | + context.update({'active_id': ref('mrp_production_servicetype_mo1')}) +- + !record {model: mrp.product.produce, id: mrp_product_produce_1}: + mode: 'consume_produce' +- + !python {model: mrp.product.produce}: | + self.do_produce(cr, uid, [ref('mrp_product_produce_1')], context=context) +- + I check production order after produced. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_servicetype_mo1")) + assert order.state == 'done', "Production order should be closed." +- + I create Bill of Materials with two service type products. +- + !record {model: mrp.bom, id: mrp_bom_test_2}: + company_id: base.main_company + name: PC Assemble SC234 + product_id: product.product_product_3 + product_qty: 1.0 + type: normal + bom_lines: + - company_id: base.main_company + name: On Site Monitoring + product_id: product.product_product_1 + product_qty: 1.0 + - company_id: base.main_company + name: On Site Assistance + product_id: product.product_product_2 + product_qty: 1.0 +- + I make the production order using BoM having two service type products. +- + !record {model: mrp.production, id: mrp_production_servicetype_2}: + product_id: product.product_product_5 + product_qty: 1.0 + bom_id: mrp_bom_test_2 + date_planned: !eval time.strftime('%Y-%m-%d %H:%M:%S') +- + I compute the data of production order. +- + !python {model: mrp.production}: | + self.action_compute(cr, uid, [ref("mrp_production_servicetype_2")], {"lang": "en_US", "tz": False, "search_default_Current": 1, + "active_model": "ir.ui.menu", "active_ids": [ref("mrp.menu_mrp_production_action")], + "active_id": ref("mrp.menu_mrp_production_action"), }) +- + I confirm the production order. +- + !workflow {model: mrp.production, action: button_confirm, ref: mrp_production_servicetype_2} +- + Now I start production. +- + !workflow {model: mrp.production, action: button_produce, ref: mrp_production_servicetype_2} +- + I check that production order in production state after start production. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_servicetype_2")) + assert order.state == 'in_production', 'Production order should be in production State.' +- + I produce product. +- + !python {model: mrp.product.produce}: | + context.update({'active_id': ref('mrp_production_servicetype_2')}) +- + !record {model: mrp.product.produce, id: mrp_product_produce_2}: + mode: 'consume_produce' +- + !python {model: mrp.product.produce}: | + self.do_produce(cr, uid, [ref('mrp_product_produce_2')], context=context) +- + I check production order after produced. +- + !python {model: mrp.production}: | + order = self.browse(cr, uid, ref("mrp_production_servicetype_2")) + assert order.state == 'done', "Production order should be closed." diff --git a/addons/mrp_operations/mrp_operations_view.xml b/addons/mrp_operations/mrp_operations_view.xml index f2d1a84b40a..9b8587349bc 100644 --- a/addons/mrp_operations/mrp_operations_view.xml +++ b/addons/mrp_operations/mrp_operations_view.xml @@ -9,7 +9,7 @@
-