def run(self): self.ensure_one() if not self.number_of_days: raise Warning( _('You must set a value for the number of days.')) if not self.employee_ids: raise Warning( _('You must select at least one employee.')) alloc_hol_ids = [] hho = self.env['hr.holidays'] auto_approve = self.auto_approve for employee in self.employee_ids: hol = hho.create({ 'name': self.name, 'number_of_days_temp': self.number_of_days, 'employee_id': employee.id, 'type': 'add', 'holiday_type': 'employee', 'holiday_status_id': self.holiday_status_id.id, }) if auto_approve: workflow.trg_validate( self._uid, 'hr.holidays', hol.id, 'validate', self._cr) alloc_hol_ids.append(hol.id) action = self.env['ir.actions.act_window'].for_xml_id( 'hr_holidays', 'open_allocation_holidays') action.update({ 'target': 'current', 'domain': [('id', 'in', alloc_hol_ids)], 'nodestroy': True, }) return action
def action_cancel(self): ''' This action_cancel overidden to avoid the cascading cancellation @param self : Object Pointer @param cr : Database Cursor @param uid : Current Logged in User @param ids : Current Records @param context : standard Dictionary @return : True ''' if not len(self.ids): return True pickings = {} for move in self: if move.state in ('confirmed', 'waiting', 'assigned', 'draft'): if move.picking_id: pickings[move.picking_id.id] = True self.write({'state': 'cancel'}) for pick_id in pickings: workflow.trg_validate(self._uid, 'stock.picking', pick_id, 'button_cancel', self._cr) ids2 = [] for res in self.read(['move_dest_id']): if res['move_dest_id']: ids2.append(res['move_dest_id'][0]) for stock_id in self.ids: workflow.trg_trigger(self._uid, 'stock.move', stock_id, self._cr) # self.action_cancel(cr,uid, ids2, context) # $$ # [removed to avoid cascading cancellation] return True
def proposition_change_state(self, proposition, state): cr, uid, context, registry = request.cr, request.uid, request.context, request.registry state_signal = { 'draft_cancel': 'proposition_draft_cancel', 'draft_open': 'proposition_draft_open', 'open_cancel': 'proposition_open_cancel', 'accept': 'proposition_open_accepted', 'reject': 'proposition_open_rejected', 'accepted_cancel': 'proposition_accepted_cancel', 'invoice': 'proposition_accepted_invoiced', 'invoiced_cancel': 'proposition_invoiced_cancel', 'confirmrefund_paid': 'proposition_confirm_refund_paid', 'confirmrefund_cancel': 'proposition_confirm_refund_cancel', } if state in state_signal.keys(): workflow.trg_validate(uid, 'marketplace.proposition', proposition.id, state_signal.get(state), cr) if state == 'pay': registry.get('marketplace.proposition').pay(cr, uid, [proposition.id]) if state == 'confirm': registry.get('marketplace.proposition').confirm(cr, uid, [proposition.id]) if state in ['cancel_draft', 'reject_draft', 'refund']: registry.get('marketplace.proposition').reset_workflow(cr, uid, [proposition.id]) user = registry.get('res.users').browse(cr, uid, uid, context=context) return self.view_announcement(proposition.announcement_id)
def order_shipped(self,cr,uid,order_id,context=None): """Shipped an order by any service like xmlrpc. @param order_id: OpenERP Order ID @param context: A standard dictionary @return: True """ if context is None: context = {} # ir_values=self.pool.get('ir.values') data = self.pool.get('sale.order').read(cr,uid,order_id,['state']) state = data['state'] if state == 'draft': self.pool.get('sale.order').action_button_confirm(cr, uid, [order_id], context=None) context['prestashop'] = 'prestashop' order_name=self.pool.get('sale.order').name_get(cr,uid,order_id) pick_id = self.pool.get('stock.picking').search(cr, uid,[('origin','=',order_name[0][1])]) if pick_id: config_values=self.pool.get('prestashop.configure').search(cr, uid,[('active','=',True)]) if config_values: self.pool.get('prestashop.configure').write(cr, uid,active_id[0],{'active':False}) # for line in self.pool.get('stock.picking').browse(cr, uid, pick_id[0]).move_lines: # self.pool.get('stock.move').action_done(cr, uid, [line.id], context) self.pool.get('stock.picking').do_transfer(cr, uid, pick_id, context) if config_values: self.pool.get('prestashop.configure').write(cr, uid,active_id[0],{'active':True}) workflow.trg_validate(uid, 'sale.order',order_id, 'ship_end', cr) return True
def pay(self, cr, uid, ids, *args): # Launch the payment of the proposition. # If an external currency is needed, it go to the confirm state transaction_obj = self.pool.get('account.wallet.transaction') self.test_access_role(cr, uid, ids, 'is_issuer', *args) for proposition in self.browse(cr, uid, ids): if proposition.state == 'invoiced': transaction_obj.prepare_move( cr, uid, [proposition.transaction_id.id], 'payment' ) skip_confirm = transaction_obj.get_skip_confirm( cr, uid, proposition.transaction_id ) if not skip_confirm: workflow.trg_validate( uid, 'marketplace.proposition', proposition.id, 'proposition_invoiced_confirm', cr ) else: workflow.trg_validate( uid, 'marketplace.proposition', proposition.id, 'proposition_invoiced_vote', cr ) self.test_vote(cr, uid, [proposition.id]) return True
def manual_invoice(self, cr, uid, ids, context=None): if context is None: context={} mod_obj = self.pool.get('ir.model.data') inv_ids = set() inv_ids1 = set() for id in ids: for record in self.pool.get('sale.order').browse(cr, uid, id).invoice_ids: inv_ids.add(record.id) #inv_ids would have old invoices if any for id in ids: workflow.trg_validate(uid, 'sale.order', id, 'manual_invoice', cr) for record in self.pool.get('sale.order').browse(cr, uid, id).invoice_ids: inv_ids1.add(record.id) inv_ids = list(inv_ids1.difference(inv_ids)) res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_form') res_id = res and res[1] or False, #manual_prestashop_invoice method is used to create an invoice on prestashop end... # if not context.has_key('prestashop'): # config_id=self.pool.get('prestashop.configure').search(cr,uid,[('active','=',True)]) # if len(config_id)>0: # self.manual_prestashop_invoice(cr,uid,ids,context) return { 'name': _('Customer Invoices'), 'view_type': 'form', 'view_mode': 'form', 'view_id': [res_id], 'res_model': 'account.invoice', 'context': "{'type':'out_invoice'}", 'type': 'ir.actions.act_window', 'nodestroy': True, 'target': 'current', 'res_id': inv_ids and inv_ids[0] or False, }
def test_supplier_open_invoice(self): self.account_payable = self.env['account.account'].search( [('type', '=', 'payable'), ('currency_id', '=', False)], limit=1)[0] # Create supplier invoice self.supplier_invoice = self.env['account.invoice'].create({ 'partner_id': self.partner.id, 'account_id': self.account_payable.id, 'date_invoice': '%s-01-01' % self.year, 'type': 'in_invoice', 'origin': 'TEST-Supplier-Inv', 'invoice_line': [(0, 0, { 'name': 'Test', 'account_id': self.account_payable.id, 'price_unit': 789.48, 'quantity': 2, })], }) # Change the state of supplier invoice from draft to open workflow.trg_validate(self.uid, 'account.invoice', self.supplier_invoice.id, 'invoice_open', self.cr) self.move_line_amount = 0.00 # Get move line amount of supplier invoice for move_line_data in self.supplier_invoice.move_id.line_id: if move_line_data.date_maturity: self.move_line_amount += move_line_data.credit # Check move line amount and supplier invoice amount is same self.assertEquals(self.supplier_invoice.amount_total, self.move_line_amount)
def do_transfer(self): ret = super(stock_picking,self).do_transfer() from openerp import workflow mrp_order_obj = self.env['mrp.production'].search([("distinct_picking_id","=",self.id)]) if mrp_order_obj: workflow.trg_validate(self._uid, 'mrp.production', mrp_order_obj.id, 'moves_ready', self._cr) return ret
def write(self, cr, uid, ids, vals, context=None): if isinstance(ids, (int, long)): ids = [ids] res = super(StockMove, self).write(cr, uid, ids, vals, context=context) from openerp import workflow if vals.get('state') == 'assigned': moves = self.browse(cr, uid, ids, context=context) mro_obj = self.pool.get('mro.order') order_ids = mro_obj.search( cr, uid, [('procurement_group_id', 'in', [x.group_id.id for x in moves])]) for order_id in order_ids: if mro_obj.test_ready(cr, uid, [order_id]): workflow.trg_validate(uid, 'mro.order', order_id, 'parts_ready', cr) # orders = mro_obj.browse(cr, uid, order_ids, context=context) # orders = list(set([x.raw_material_production_id.id for x in moves if x.raw_material_production_id and x.raw_material_production_id.state == 'confirmed'])) # for order_id in orders: # if self.pool.get('mrp.production').test_ready(cr, uid, [order_id]): # workflow.trg_validate(uid, 'mrp.production', order_id, 'moves_ready', cr) return res # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
def reset_workflow(self, cr, uid, ids, *args): # Called by workflow, launch needed action depending # of the next state and reset the workflow transaction_obj = self.pool.get('account.wallet.transaction') for proposition in self.browse(cr, uid, ids): state = proposition.state role_to_test = 'is_user' if state == 'rejected': role_to_test = 'is_announcer' elif state == 'paid': role_to_test = 'is_receiver' self.test_access_role(cr, uid, ids, role_to_test, *args) if state in ['cancel', 'rejected', 'paid']: workflow.trg_delete(uid, 'marketplace.proposition', proposition.id, cr) workflow.trg_create(uid, 'marketplace.proposition', proposition.id, cr) if state == 'paid': skip_confirm = transaction_obj.get_skip_confirm( cr, uid, proposition.transaction_id) if not skip_confirm: workflow.trg_validate(uid, 'marketplace.proposition', proposition.id, 'proposition_draft_confirm_refund', cr) else: workflow.trg_validate( uid, 'marketplace.proposition', proposition.id, 'proposition_paid_cancel_through_draft', cr) return True
def test_cancel_full_line(self): self.common_test() line_to_cancel = self.purchase_order.order_line[0] lines_to_invoice = self.purchase_order.order_line\ .filtered(lambda r: r.id != line_to_cancel.id) ctx = self.context.copy() ctx.update({'active_ids': lines_to_invoice.ids}) wizard = self.env['purchase.order.line_invoice']\ .with_context(ctx).create({}) # I click on make invoice button wizard.with_context(ctx).makeInvoices() ctx.update({'active_ids': line_to_cancel.id}) # I check if lines are invoiced invoice_lines = self.inv_line_obj\ .search([('purchase_line_id', 'in', lines_to_invoice.ids)]) self.assertEqual(len(invoice_lines), len(lines_to_invoice.ids)) # I get the created invoice invoice = invoice_lines[0].invoice_id # I validate the invoice workflow.trg_validate(self.uid, 'account.invoice', invoice.id, 'invoice_open', self.cr) # I cancel quantity quantity_to_cancel = line_to_cancel.product_qty wizard = self.env['purchase.order.line_cancel_quantity']\ .with_context(ctx).create({}) # I change the quantity on the line that will be cancelled wizard.line_ids[0].cancelled_qty = quantity_to_cancel wizard.cancel_quantity() # I check the cancelled quantity on purchase line self.assertEqual(line_to_cancel.cancelled_qty, quantity_to_cancel) # I check if the line is fully invoiced self.assertTrue(line_to_cancel.fully_invoiced) # I check if the purchase order is invoiced line_to_cancel.order_id.invalidate_cache() self.assertTrue(line_to_cancel.order_id.invoiced)
def fees_register_confirm(self): student_pool = self.env['student.student'] slip_pool = self.env['student.payslip'] student_ids = student_pool.search([]) for vals in self.browse(self.ids): for stu in student_ids: old_slips = slip_pool.search([('student_id', '=', stu.id), ('date', '=', vals.date)]) if old_slips: old_slips.write({'register_id':vals.id}) for sid in old_slips: workflow.trg_validate(self._uid, 'student.payslip', sid, 'payslip_confirm', self._cr) else: res = { 'student_id':stu.id, 'register_id':vals.id, 'name':vals.name, 'date':vals.date, 'journal_id': vals.journal_id.id, 'period_id': vals.period_id.id, 'company_id': vals.company_id.id } slip_id = slip_pool.create(res) workflow.trg_validate(self._uid, 'student.payslip', slip_id, 'payslip_confirm', self._cr) amount = 0 for datas in self.browse(self.ids): for data in datas.line_ids: amount = amount + data.total student_fees_register_vals = {'total_amount':amount} datas.write(student_fees_register_vals) self.write({'state' : 'confirm'}) return True
def test_51_validate_2_invoice_with_same_ref_supplier_contact(self): 'Test to validate 2 invoices with same reference, but a supplier '\ 'is a contact' invoice = self.inv_demo.copy() invoice2 = self.inv_demo.copy() invoice.write({ 'supplier_invoice_number': 'Test50', 'partner_id': self.partner_demo1.id }) invoice2.write({ 'supplier_invoice_number': 'Test50', 'partner_id': self.partner_demo_contact.id }) workflow.trg_validate( self.uid, 'account.invoice', invoice.id, 'invoice_open', self.cr) self.assertEquals( invoice.state, 'open', 'This invoice has not state in open') self.cr.commit() with self.assertRaisesRegexp( exceptions.Warning, 'Error you can not validate the invoice with ' 'supplier invoice number duplicated.'): workflow.trg_validate( self.uid, 'account.invoice', invoice2.id, 'invoice_open', self.cr)
def generate_initial_order(self): """Method that creates an initial order with all the agreement lines """ self.ensure_one() # Add only active lines agreement_lines = self.mapped('agreement_line').filtered('active_chk') order_id = self.create_order(self.start_date, agreement_lines) # Update agreement state self.write({'state': 'first'}) # Confirm order workflow.trg_validate( self.env.uid, 'sale.order', order_id, 'order_confirm', self.env.cr) # Get view to show view = self.env.ref('sale.view_order_form') # Return view with order created return { 'domain': "[('id', '=', %s)]" % order_id, 'view_type': 'form', 'view_mode': 'form', 'res_model': 'sale.order', 'context': self.env.context, 'res_id': order_id, 'view_id': [view.id], 'type': 'ir.actions.act_window', 'nodestroy': True }
def test_20_validate_invoice_without_reference(self): 'Test to validate a invoice without reference' invoice = self.inv_demo.copy() workflow.trg_validate( self.uid, 'account.invoice', invoice.id, 'invoice_open', self.cr) self.assertEquals( invoice.state, 'open', 'This invoice has not state in open')
def button_purchase_temp(self): for po in self: if po.amount_total < 10000: workflow.trg_validate(self._uid, 'purchase.order', po.id, 'purchase_confirm', self._cr) else: workflow.trg_validate(self._uid, 'purchase.order', po.id, 'purchase_tempo', self._cr) return True
def export(self): for order_id in self.env.context.get('active_ids', []): order = self.env['payment.order'].browse(order_id) cnab = Cnab.get_cnab(order.mode.bank_id.bank_bic, order.mode_type.code)() remessa = cnab.remessa(order) suf_arquivo = order.get_next_sufixo() if order.mode.type.code == '240': self.name = 'CB%s%s.REM' % (time.strftime('%d%m'), str(order.file_number)) elif order.mode.type.code == '400': self.name = 'CB%s%s.REM' % (time.strftime('%d%m'), str(suf_arquivo)) elif order.mode.type.code == '500': self.name = 'PG%s%s.REM' % (time.strftime('%d%m'), str(order.file_number)) self.state = 'done' self.cnab_file = base64.b64encode(remessa) workflow.trg_validate(self.env.uid, 'payment.order', order_id, 'done', self.env.cr) return { 'type': 'ir.actions.act_window', 'res_model': self._name, 'view_mode': 'form', 'view_type': 'form', 'res_id': self.id, 'target': 'new', }
def action_ship_create(self, cr, uid, ids, context=None): res = super(SaleOrder, self).action_ship_create(cr, uid, ids, context=context) for order in self.browse(cr, uid, ids, context): for picking in order.picking_ids: vals = {'number_of_packages': order.parcels} if order.incoterm: vals.update({'incoterm_id': order.incoterm.id}) if order.transportation_method_id: vals.update({ 'delivery_methods': order.transportation_method_id.id }) self.pool.get('stock.picking').write(cr, uid, [picking.id], vals, context=context) if order.create_ddt: ddt_data = { 'partner_id': order.partner_id.id, } ddt_pool = self.pool['stock.ddt'] ddt_id = ddt_pool.create(cr, uid, ddt_data, context=context) for picking in order.picking_ids: self.pool.get('stock.picking').write( cr, uid, [picking.id], {'ddt_id': ddt_id}) picking.ddt_id = ddt_id workflow.trg_validate(uid, 'stock.ddt', ddt_id, 'ddt_confirm', cr) return res
def save_sepa(self, cr, uid, ids, context=None): """Save the SEPA Direct Debit file: mark all payments in the file as 'sent'. Write 'last debit date' on mandate and set oneoff mandate to expired. """ sepa_export = self.browse(cr, uid, ids[0], context=context) self.pool.get('banking.export.sdd').write( cr, uid, sepa_export.file_id.id, {'state': 'sent'}, context=context) for order in sepa_export.payment_order_ids: workflow.trg_validate(uid, 'payment.order', order.id, 'done', cr) mandate_ids = [line.mandate_id.id for line in order.line_ids] self.pool['account.banking.mandate'].write( cr, uid, mandate_ids, {'last_debit_date': datetime.today().strftime('%Y-%m-%d')}, context=context) to_expire_ids = [] first_mandate_ids = [] for line in order.line_ids: if line.mandate_id.type == 'oneoff': to_expire_ids.append(line.mandate_id.id) elif line.mandate_id.type == 'recurrent': seq_type = line.mandate_id.recurrent_sequence_type if seq_type == 'final': to_expire_ids.append(line.mandate_id.id) elif seq_type == 'first': first_mandate_ids.append(line.mandate_id.id) self.pool['account.banking.mandate'].write( cr, uid, to_expire_ids, {'state': 'expired'}, context=context) self.pool['account.banking.mandate'].write( cr, uid, first_mandate_ids, { 'recurrent_sequence_type': 'recurring', 'sepa_migrated': True, }, context=context) return {'type': 'ir.actions.act_window_close'}
def create_invoice(self, invoice_type, amount): year = datetime.now().year self.invoice = self.env['account.invoice'].create({ 'partner_id': self.partner.id, 'account_id': self.account.id, 'date_invoice': '%s-01-01' % year, 'type': invoice_type, 'supplier_invoice_number': 'TEST1234', 'invoice_line': [(0, 0, { 'name': 'Test', 'account_id': self.account_expense.id, 'price_unit': amount, 'quantity': 1, })], }) workflow.trg_validate( self.uid, 'account.invoice', self.invoice.id, 'invoice_open', self.cr) self.voucher = self.env['account.voucher'].create({ 'date': '%s-01-02' % year, 'name': "test", 'account_id': self.account.id, 'partner_id': self.partner.id, 'type': 'payment', })
def setUp(self): super(TestAccountVoucher, self).setUp() self.env.user.company_id.disable_voucher_auto_lines = True year = datetime.now().year self.account = self.env['account.account'].search( [('type', '=', 'receivable'), ('currency_id', '=', False)], limit=1)[0] self.account_credit_run_model = self.env['credit.control.run'] self.partner = self.env['res.partner'].create({ 'name': 'Test', 'customer': True, }) self.credit_control_policy = self.env.ref( 'account_credit_control.credit_control_3_time') self.invoice = self.env['account.invoice'].create({ 'partner_id': self.partner.id, 'account_id': self.account.id, 'date_invoice': '%s-01-01' % year, 'type': 'out_invoice', 'origin': 'TEST1234', 'invoice_line': [(0, 0, { 'name': 'Test', 'account_id': self.account.id, 'price_unit': 234.56, 'quantity': 1, })], }) workflow.trg_validate(self.uid, 'account.invoice', self.invoice.id, 'invoice_open', self.cr) self.voucher = self.env['account.voucher'].create({ 'date': '%s-01-02' % year, 'name': "test voucher", 'amount': 11.00, 'account_id': self.account.id, 'partner_id': self.partner.id, 'type': 'receipt', }) voucher_data = self.voucher onchange_res = voucher_data.onchange_partner_id( voucher_data.partner_id.id, voucher_data.journal_id.id, voucher_data.amount, voucher_data.currency_id.id, voucher_data.type, voucher_data.date) lines = [(0, 0, line_data) for line_data in onchange_res['value']['line_cr_ids']] self.voucher.write({'line_cr_ids': lines})
def _get_auto_invoice(self): for rec in self: group = rec.procurement_group_id if group and rec.auto_invoice and rec.order_policy == 'manual': if all([proc.state in ['cancel', 'done'] for proc in group.procurement_ids]): invoice = self.env['sale.order'].sudo().action_invoice_create() if invoice: _logger.debug( 'Automaticly Created Invoice: %s',( invoice ) ) rec.auto_invoiced = True _logger.debug('Validating Invoice: %s',(invoice)) workflow.trg_validate( self.sudo()._uid, 'account.invoice', invoice, 'invoice_open', self._cr ) else: _logger.debug( 'Error automatic Invoice creation for order: %s',( rec.id ) ) rec.auto_invoiced = False else: rec.auto_invoiced = False
def test_make_invoice_draft_invoice(self): self.purchase_order.invoice_method = 'order' workflow.trg_validate(self.uid, 'purchase.order', self.purchase_order.id, 'purchase_confirm', self.cr) self.assertEqual(self.po_line_1.invoice_lines.discount, 50) self.assertEqual(self.po_line_2.invoice_lines.discount, 30)
def _get_auto_invoice(self): for rec in self: group = rec.procurement_group_id if group and rec.auto_invoice and rec.order_policy == 'manual': if all([ proc.state in ['cancel', 'done'] for proc in group.procurement_ids ]): invoice = self.env['sale.order'].sudo( ).action_invoice_create() if invoice: _logger.debug('Automaticly Created Invoice: %s', (invoice)) rec.auto_invoiced = True _logger.debug('Validating Invoice: %s', (invoice)) workflow.trg_validate(self.sudo()._uid, 'account.invoice', invoice, 'invoice_open', self._cr) else: _logger.debug( 'Error automatic Invoice creation for order: %s', (rec.id)) rec.auto_invoiced = False else: rec.auto_invoiced = False
def _create_invoice(self, date, amount, start_date, end_date): inv_id = self.inv_model.create( self.cr, self.uid, { 'journal_id': self.ref('account.expenses_journal'), 'date_invoice': self._date(date), 'account_id': self.ref('account.a_recv'), 'partner_id': self.ref('base.res_partner_17'), 'type': 'in_invoice', 'invoice_line': [(0, 0, { 'name': 'expense', 'price_unit': amount, 'quantity': 1, 'account_id': self.ref('account.a_expense'), 'start_date': self._date(start_date), 'end_date': self._date(end_date), })], }) workflow.trg_validate(self.uid, 'account.invoice', inv_id, 'invoice_open', self.cr) inv = self.inv_model.browse(self.cr, self.uid, inv_id) self.assertEqual(amount, inv.amount_untaxed) return inv_id
def common_test(self): self.purchase_order = self.env.ref('purchase.purchase_order_1') # I change invoice method to 'based on purchase order line' self.purchase_order.invoice_method = 'manual' # I change the quantity on the first line to 10 self.purchase_order.order_line[0].product_qty = 10 # I confirm the purchase order workflow.trg_validate(self.uid, 'purchase.order', self.purchase_order.id, 'purchase_confirm', self.cr) # I check if the purchase order is confirmed self.purchase_order.invalidate_cache() self.assertEqual(self.purchase_order.state, 'approved', "Purchase order's state isn't correct") # I get lines to invoiced purchase_lines = self.purchase_order.order_line # I get menu item action menu = self.env.ref('purchase.purchase_line_form_action2') self.domain = safe_eval(menu.domain) self.domain.extend([('order_id', '=', self.purchase_order.id), ('fully_invoiced', '=', False)]) purchase_line_domain = self.po_line_obj.search(self.domain) # I check if all lines is on the view's result self.assertEqual(purchase_line_domain, purchase_lines, "lines aren't on the menu")
def reset_workflow(self, cr, uid, ids, *args): # Called by workflow, launch needed action depending # of the next state and reset the workflow for transaction in self.browse(cr, uid, ids): state = transaction.state role_to_test = 'is_sender' if state == 'done': role_to_test = 'is_receiver' self.test_access_role(cr, uid, ids, role_to_test, *args) workflow.trg_delete(uid, 'exchange.transaction', transaction.id, cr) workflow.trg_create(uid, 'exchange.transaction', transaction.id, cr) if state == 'done': skip_confirm = self.get_skip_confirm(cr, uid, transaction) if not skip_confirm: workflow.trg_validate(uid, 'exchange.transaction', transaction.id, 'transaction_draft_confirm_refund', cr) else: workflow.trg_validate( uid, 'exchange.transaction', transaction.id, 'transaction_done_cancel_through_draft', cr) return True
def order_shipped(self, cr, uid, order_id, context=None): """Shipped an order by any service like xmlrpc. @param order_id: OpenERP Order ID @param context: A standard dictionary @return: True """ if context is None: context = {} # ir_values=self.pool.get('ir.values') data = self.pool.get('sale.order').read(cr, uid, order_id, ['state']) state = data['state'] if state == 'draft': self.pool.get('sale.order').action_button_confirm(cr, uid, [order_id], context=None) context['prestashop'] = 'prestashop' order_name = self.pool.get('sale.order').name_get(cr, uid, order_id) pick_id = self.pool.get('stock.picking').search( cr, uid, [('origin', '=', order_name[0][1])]) if pick_id: config_values = self.pool.get('prestashop.configure').search( cr, uid, [('active', '=', True)]) if config_values: self.pool.get('prestashop.configure').write( cr, uid, active_id[0], {'active': False}) # for line in self.pool.get('stock.picking').browse(cr, uid, pick_id[0]).move_lines: # self.pool.get('stock.move').action_done(cr, uid, [line.id], context) self.pool.get('stock.picking').do_transfer(cr, uid, pick_id, context) if config_values: self.pool.get('prestashop.configure').write( cr, uid, active_id[0], {'active': True}) workflow.trg_validate(uid, 'sale.order', order_id, 'ship_end', cr) return True
def test_close(self, cr, uid, ids, context=None): # Auto close the announcement when all available are sold for announcement in self.browse(cr, uid, ids, context=context): if announcement.state == 'open' and announcement.quantity_available == 0 and not announcement.infinite_qty: workflow.trg_validate(SUPERUSER_ID, 'marketplace.announcement', announcement.id, 'announcement_open_done', cr)
def test_20_validate_invoice_without_reference(self): """Validate an invoice without reference""" invoice = self.inv_demo.copy() workflow.trg_validate(self.uid, 'account.invoice', invoice.id, 'invoice_open', self.cr) self.assertEquals(invoice.state, 'open', 'This invoice has not state in open')
def test_vote(self, cr, uid, ids, context=None): # Check the votes, to know if all required votes are made and if we can close the proposition transaction_obj = self.pool.get('account.wallet.transaction') vote_obj = self.pool.get('vote.vote') for proposition in self.browse(cr, uid, ids, context=context): vote_user = False vote_announcer = False user_partner_id = proposition.sender_id.id announcer_partner_id = proposition.receiver_id.id vote_ids = vote_obj.search( cr, uid, [('model', '=', 'marketplace.proposition'), ('res_id', '=', proposition.id), ('partner_id', 'in', [user_partner_id, announcer_partner_id]) ], context=context) for vote in vote_obj.browse(cr, uid, vote_ids, context=context): if vote.partner_id.id == user_partner_id: vote_user = vote if vote.partner_id.id == announcer_partner_id: vote_announcer = vote if vote_user and vote_user.is_complete and vote_announcer and vote_announcer.is_complete: workflow.trg_validate(uid, 'marketplace.proposition', proposition.id, 'proposition_vote_paid', cr) transaction_obj.write(cr, uid, [proposition.transaction_id.id], {'state': 'done'}, context=context) workflow.trg_delete(uid, 'account.wallet.transaction', proposition.transaction_id.id, cr)
def import_one_chunk(session, res_model, att_id, options): model_obj = session.pool[res_model] context = session.context.copy() if not session.context.get('lang', False): context.update({'lang': session.env.user.lang}) fields, data = _read_csv_attachment(session, att_id, options) result = model_obj.load(session.cr, session.uid, fields, data, context=context) error_message = [ message['message'] for message in result['messages'] if message['type'] == 'error' ] if error_message: raise FailedJobError('\n'.join(error_message)) if res_model == 'account.invoice': if result['ids']: from openerp import workflow for res_id in result['ids']: workflow.trg_validate(session.uid, res_model, res_id, 'invoice_open', session.cr) # model_obj.browse(session.cr, session.uid, result['ids']).signal_workflow('invoice_open') return result
def fees_register_confirm(self): student_pool = self.env['student.student'] slip_pool = self.env['student.payslip'] student_ids = student_pool.search([]) for vals in self.browse(self.ids): for stu in student_ids: old_slips = slip_pool.search([('student_id', '=', stu.id), ('date', '=', vals.date)]) if old_slips: old_slips.write({'register_id': vals.id}) for sid in old_slips: workflow.trg_validate(self._uid, 'student.payslip', sid, 'payslip_confirm', self._cr) else: res = { 'student_id': stu.id, 'register_id': vals.id, 'name': vals.name, 'date': vals.date, 'journal_id': vals.journal_id.id, 'period_id': vals.period_id.id, 'company_id': vals.company_id.id } slip_id = slip_pool.create(res) workflow.trg_validate(self._uid, 'student.payslip', slip_id, 'payslip_confirm', self._cr) amount = 0 for datas in self.browse(self.ids): for data in datas.line_ids: amount = amount + data.total student_fees_register_vals = {'total_amount': amount} datas.write(student_fees_register_vals) self.write({'state': 'confirm'}) return True
def test_invoice(self): invoice_obj = self.registry('account.invoice') move_line_obj = self.registry('account.move.line') invoice_id = create_simple_invoice(self, self.cr, self.uid, context=self.context) workflow.trg_validate(self.uid, 'account.invoice', invoice_id, 'invoice_open', self.cr) invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id], context=self.context)[0] move_line_ids = move_line_obj\ .search(self.cr, self.uid, [('account_id.type', 'in', ['payable', 'receivable']), ('invoice.id', '=', invoice.id)]) move_line = move_line_obj.browse(self.cr, self.uid, move_line_ids)[0] self.assertEqual(invoice.blocked, move_line.blocked, 'Blocked values are not equals') move_line_obj.write(self.cr, self.uid, move_line_ids, {'blocked': True}) invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id], context=self.context)[0] move_line = move_line_obj.browse(self.cr, self.uid, move_line_ids)[0] self.assertEqual(invoice.blocked, move_line.blocked, 'Blocked values are not equals')
def test_make_invoice_draft_invoice(self): self.purchase_order.invoice_method = 'order' workflow.trg_validate( self.uid, 'purchase.order', self.purchase_order.id, 'purchase_confirm', self.cr) self.assertEqual(self.po_line_1.invoice_lines.discount, 50) self.assertEqual(self.po_line_2.invoice_lines.discount, 30)
def confirm_current_orders_planned(self): orders = self.search([]).mapped('order_line').filtered( lambda x: not x.confirmed and x.date <= fields.Date.today()) for order in orders: workflow.trg_validate( self.env.uid, 'sale.order', order.id, 'order_confirm', self.env.cr)
def write(self, cr, uid, ids, vals, context=None): if isinstance(ids, (int, long)): ids = [ids] res = super(stock_move, self).write(cr, uid, ids, vals, context=context) from openerp import workflow if vals.get('state') in ['done', 'cancel']: po_to_check = [] for move in self.browse(cr, uid, ids, context=context): if move.purchase_line_id and move.purchase_line_id.order_id: order = move.purchase_line_id.order_id order_id = order.id # update linked purchase order as superuser as the warehouse # user may not have rights to access purchase.order if self.pool.get('purchase.order').test_moves_done( cr, uid, [order_id], context=context): workflow.trg_validate(SUPERUSER_ID, 'purchase.order', order_id, 'picking_done', cr) if self.pool.get('purchase.order').test_moves_except( cr, uid, [order_id], context=context): workflow.trg_validate(SUPERUSER_ID, 'purchase.order', order_id, 'picking_cancel', cr) if order_id not in po_to_check and vals[ 'state'] == 'cancel' and order.invoice_method == 'picking': po_to_check.append(order_id) # Some moves which are cancelled might be part of a PO line which is partially # invoiced, so we check if some PO line can be set on "invoiced = True". if po_to_check: self.pool.get('purchase.order')._set_po_lines_invoiced( cr, uid, po_to_check, context=context) return res
def test_close(self, cr, uid, ids, context=None): # Auto close the announcement when all available are sold for announcement in self.browse(cr, uid, ids, context=context): if announcement.state == 'open' and announcement.quantity_available == 0 and not announcement.infinite_qty: workflow.trg_validate( SUPERUSER_ID, 'marketplace.announcement', announcement.id, 'announcement_open_done', cr )
def setUp(self): super(TestAnalyticPartner, self).setUp() product = self.env.ref('product.product_product_5') self.analytic_account = self.env['account.analytic.account'].create({ 'name': 'Test Analytic Account', 'state': 'draft', 'type': 'normal' }) self.invoice = self.env['account.invoice'].create({ 'journal_id': self.env.ref('account.sales_journal').id, 'partner_id': self.env.ref('base.res_partner_3').id, 'account_id': self.env.ref('account.a_recv').id, 'invoice_line': [(0, 0, { 'product_id': product.id, 'name': 'Test', 'account_analytic_id': self.analytic_account.id, 'quantity': 10.0, })], }) workflow.trg_validate(self.uid, 'account.invoice', self.invoice.id, 'invoice_open', self.cr)
def test_vote(self, cr, uid, ids, context=None): # Check the votes, to know if all required votes are made and if we can close the proposition transaction_obj = self.pool.get('account.wallet.transaction') vote_obj = self.pool.get('vote.vote') for proposition in self.browse(cr, uid, ids, context=context): vote_user = False vote_announcer = False user_partner_id = proposition.sender_id.id announcer_partner_id = proposition.receiver_id.id vote_ids = vote_obj.search( cr, uid, [ ('model', '=', 'marketplace.proposition'), ('res_id', '=', proposition.id), ('partner_id', 'in', [user_partner_id, announcer_partner_id]) ], context=context) for vote in vote_obj.browse(cr, uid, vote_ids, context=context): if vote.partner_id.id == user_partner_id: vote_user = vote if vote.partner_id.id == announcer_partner_id: vote_announcer = vote if vote_user and vote_user.is_complete and vote_announcer and vote_announcer.is_complete: workflow.trg_validate(uid, 'marketplace.proposition', proposition.id, 'proposition_vote_paid', cr) transaction_obj.write(cr, uid, [proposition.transaction_id.id], {'state': 'done'}, context=context) workflow.trg_delete(uid, 'account.wallet.transaction', proposition.transaction_id.id, cr)
def action_valider(self): if self.categorie_type_event == 'jrslegaux': xs = self.env['hr.holidays'].create({ 'holiday_type': 'employee', 'name': self.event_type.name, 'number_of_days_temp': self.duree_jr_leg, 'type': 'add', 'employee_id': self.employee_id.id, 'state': 'cancel', 'holiday_status_id': self.event_type.holiday.id }) workflow.trg_validate(self._uid, 'hr.holidays', xs.id, 'validate', self._cr) #return self.write({'status': 'valide'}) self.status = "valide" if self.rupture_contrat: contrat_id = self.env['hr.contract'].search([ ('employee_id', '=', self.employee_id.id) ]) self.contract_id = contrat_id contrat_id.date_end = self.date payslips = self.event_id # if payslips: # for p in payslips: # p.calculer_nbr_jr_acquis() self.date_validation = datetime.now() return self.status
def reset_workflow(self, cr, uid, ids, *args): # Called by workflow, launch needed action depending of the next state and reset the workflow transaction_obj = self.pool.get('account.wallet.transaction') for proposition in self.browse(cr, uid, ids): state = proposition.state role_to_test = 'is_user' if state == 'rejected': role_to_test = 'is_announcer' elif state == 'paid': role_to_test = 'is_receiver' self.test_access_role(cr, uid, ids, role_to_test, *args) workflow.trg_delete(uid, 'marketplace.proposition', proposition.id, cr) workflow.trg_create(uid, 'marketplace.proposition', proposition.id, cr) if state == 'paid': skip_confirm = transaction_obj.get_skip_confirm(cr, uid, proposition.transaction_id) if not skip_confirm: workflow.trg_validate( uid, 'marketplace.proposition', proposition.id, 'proposition_draft_confirm_refund', cr ) else: workflow.trg_validate( uid, 'marketplace.proposition', proposition.id, 'proposition_paid_cancel_through_draft', cr ) return True
def pay(self, cr, uid, ids, *args): # Launch the payment of the proposition. # If an external currency is needed, it go to the confirm state transaction_obj = self.pool.get('account.wallet.transaction') self.test_access_role(cr, uid, ids, 'is_sender', *args) for proposition in self.browse(cr, uid, ids): if proposition.state == 'invoiced': transaction_obj.prepare_move( cr, uid, [proposition.transaction_id.id], 'payment' ) skip_confirm = transaction_obj.get_skip_confirm( cr, uid, proposition.transaction_id ) if not skip_confirm: workflow.trg_validate( uid, 'marketplace.proposition', proposition.id, 'proposition_invoiced_confirm', cr ) else: workflow.trg_validate( uid, 'marketplace.proposition', proposition.id, 'proposition_invoiced_vote', cr ) self.test_vote(cr, uid, [proposition.id]) return True
def test_post_move_invoice(self): invoice = create_simple_invoice(self) workflow.trg_validate(self.uid, 'account.invoice', invoice.id, 'invoice_open', self.cr) move_lines = invoice.move_id.line_id self.assertRaises(exceptions.Warning, move_lines.write, {'ref': 'test'})
def create_order_invoice(self, cr, uid, order_id, context=None): """Create an order Invoice by any service like xmlrpc. @param order_id: OpenERP Order ID @param context: A standard dictionary @return: OpenERP Invoice ID """ if context is None: context = {} context['prestashop'] = 'prestashop' active_id = self.pool.get('prestashop.configure').search( cr, uid, [('active', '=', True)]) if active_id: self.pool.get('prestashop.configure').write( cr, uid, active_id[0], {'active': False}) inv_ids = self.pool.get('sale.order').manual_invoice( cr, uid, [order_id], context) invoice_id = inv_ids['res_id'] if context.has_key('invoice_date'): self.pool.get('account.invoice').write( cr, uid, invoice_id, { 'date_invoice': context.get('invoice_date', False), 'date_due': context.get('invoice_date', False) }) workflow.trg_validate(uid, 'account.invoice', invoice_id, 'invoice_open', cr) if active_id: self.pool.get('prestashop.configure').write( cr, uid, active_id[0], {'active': True}) return invoice_id
def reply(self, context=None, wkf_trigger=''): message = dict(self.ticket_id._get_reject_reasons())[self.ticket_reject_reason] if(self.ticket_reject_descr): message += u' ### %s ###'.encode("utf8") % self.ticket_reject_descr.encode("utf8") value = { 'message': message, 'helpdesk_id': self.ticket_id.id, 'user_id': self._uid, } reply_id = self.env['helpdesk.qa'].create(value) if self.attachment: attach_value = { 'name': self.attachment_name, 'db_datas': self.attachment, 'res_model': 'helpdesk.qa', 'res_id': reply_id.id, 'helpdesk_qa_id': reply_id.id, } self.env['ir.attachment'].create(attach_value) # ---- send mail to support for the new reply to ticket self.env['crm.helpdesk'].send_notification_mail( template_xml_id='email_template_ticket_reply', object_class='helpdesk.qa', object_id=reply_id.id) workflow.trg_validate(self._uid, 'crm.helpdesk', self.ticket_id.id, 'ticket_deleted', self._cr) return {'type': 'ir.actions.act_window_close'}
def reset_workflow(self, cr, uid, ids, *args): # Called by workflow, launch needed action depending # of the next state and reset the workflow for transaction in self.browse(cr, uid, ids): state = transaction.state role_to_test = 'is_sender' if state == 'done': role_to_test = 'is_receiver' self.test_access_role(cr, uid, ids, role_to_test, *args) workflow.trg_delete( uid, 'exchange.transaction', transaction.id, cr ) workflow.trg_create( uid, 'exchange.transaction', transaction.id, cr ) if state == 'done': skip_confirm = self.get_skip_confirm(cr, uid, transaction) if not skip_confirm: workflow.trg_validate( uid, 'exchange.transaction', transaction.id, 'transaction_draft_confirm_refund', cr ) else: workflow.trg_validate( uid, 'exchange.transaction', transaction.id, 'transaction_done_cancel_through_draft', cr ) return True
def test_10_validate_invoice_with_reference_unique(self): 'Test to validate a invoice with reference unique' invoice = self.inv_demo.copy() invoice.write({'supplier_invoice_number': 'Test10'}) workflow.trg_validate( self.uid, 'account.invoice', invoice.id, 'invoice_open', self.cr) self.assertEquals( invoice.state, 'open', 'This invoice has not state in open')
def remove_order(self, cr, uid, ids, second_order_id = False, context = None): if ids and second_order_id: line_ids = [line.id for line in self.browse(cr, uid, second_order_id, context = context).lines] self.pool.get("pos.order.line").write(cr, uid, line_ids, {"order_id" : ids[0]}) workflow.trg_validate(uid, 'pos.order', second_order_id, 'cancel', cr) if not ids and second_order_id: workflow.trg_validate(uid, 'pos.order', second_order_id, 'cancel', cr) return True
def test_make_invoice_from_picking(self): self.purchase_order.invoice_method = 'picking' workflow.trg_validate( self.uid, 'purchase.order', self.purchase_order.id, 'purchase_confirm', self.cr) self.purchase_order.picking_ids.action_invoice_create( self.env.ref('account.expenses_journal').id, type='in_invoice') self.assertEqual(self.po_line_1.invoice_lines.discount, 50) self.assertEqual(self.po_line_2.invoice_lines.discount, 30)
def submits_all_lines(self,cr,uid): ''' Submits all the attendance.line created today and return their ID's ''' #search for all the attendance.line that were created and left in pending state today line_ids = self.pool.get('attendance.line').search(cr,uid,[('state','=','pending'),('date','=',datetime.now(timezone('Asia/Kolkata')).date().strftime("%Y-%m-%d"))], offset=0, limit=200, order=None, context=None, count=False) for line in line_ids: workflow.trg_validate(SUPERUSER_ID, 'attendance.line', line, 'change_pending_done', cr) return line_ids
def do_transfer(self): res = super(product_expense_picking, self).do_transfer() if res: expense = self.env['product.expense'].search([('name', '=', self.origin)]) if expense: for line in expense: line.ref_no = self.id workflow.trg_validate(self.env.user.id, 'product.expense', line.id, 'ship_end', self.env.cr) return res
def test_make_invoice_from_picking(self): self.purchase_order.invoice_method = 'picking' workflow.trg_validate( self.uid, 'purchase.order', self.purchase_order.id, 'purchase_confirm', self.cr) invoice_ids = self.purchase_order.picking_ids.action_invoice_create( self.env.ref('account.expenses_journal').id, type='in_invoice') invoice = self.env['account.invoice'].browse(invoice_ids[0]) self.assertEqual(invoice.invoice_line[0].discount, 50) self.assertEqual(invoice.invoice_line[1].discount, 30)
def action_cancel_draft_invoices(self): assert len(self) == 1, \ 'This option should only be used for a single id at a time.' # Get all unpaid invoice for invoice in self.invoice_ids: if invoice.state in ('draft'): workflow.trg_validate( self._uid, 'account.invoice', invoice.id, 'invoice_cancel', self._cr) return True
def write(self, vals): res = super(stock_move, self).write(vals) if vals.get('state') == 'assigned': orders = list(set([x.raw_material_production_id for x in self if x.raw_material_production_id and x.raw_material_production_id.state == 'Component Ready'])) for order_id in orders: if order_id.test_ready(): workflow.trg_validate(self.env.uid, 'mrp.production', order_id.id, 'moves_ready', self.env.cr) return res #end of stock_move()
def test_draft_move_invoice(self): invoice = create_simple_invoice(self) workflow.trg_validate(self.uid, 'account.invoice', invoice.id, 'invoice_open', self.cr) move = invoice.move_id move_lines = move.line_id move.with_context({'from_parent_object': True})\ .write({'state': 'draft'}) self.assertRaises(exceptions.Warning, move_lines.write, {'credit': 0.0})
def test_post_move_invoice_ref(self): invoice = create_simple_invoice(self) workflow.trg_validate(self.uid, 'account.invoice', invoice.id, 'invoice_open', self.cr) move_lines = invoice.move_id.line_id # here, normally no exception is raised in standard code. # It's just to verify if it's # possible to modify ref field in a post account_move_line move_lines.with_context({'from_parent_object': True})\ .write({'ref': 'test'})