Exemple #1
0
 def create_sale_offer(self):
     """
         Fonction qui permet de créer la vente liée au partenaire et au produit
     """
     sale_obj = self.env['sale.order']
     data_obj = self.env['ir.model.data']
     offer_obj = self.env['specific.offer']
     for wizard in self:
         offer = wizard.offer_id
         if offer.partner_id and offer.product_id:
             #Création de la vente avec le produit et le partenaire
             so_line = {offer.product_id: {'option_lines_ids': [(0,0, {'option_id': x.option_id.id, 'price_unit': x.price_unit}) for x in offer.option_ids], 
                                           'variant_category_value_ids': [(6, 0, [y.id for y in offer.variant_value_ids])],
                                           'sec_uom_qty': wizard.quantity}}
             so_line[offer.product_id].update(offer_obj.add_product_line_values(offer))
             new_sale = sale_obj.create_sale(offer.partner_id, so_line, wizard.date, {})
             #On passe l'offre au statut validé et la CRM liée à "Gagnée"
             offer.state = 'validated'
             if offer.crm_id:
                 object_model, object_id = data_obj.get_object_reference('crm_openprod', 'crm_state_won')
                 if object_model and object_model == 'crm.state':
                     offer.crm_id.write({'state_id': object_id})
             
             #On renvoie la vue de la vente créée
             if new_sale:
                 action_dict = get_form_view(self, 'sale.sale_order_see_form')
                 if action_dict and action_dict.get('id') and action_dict.get('type'):
                     action = self.env[action_dict['type']].browse(action_dict['id'])
                     action_struc = action.read()
                     action_struc[0]['res_id'] = new_sale.id
                     action_struc = action_struc[0]
                     return action_struc
                 
         return True
Exemple #2
0
    def create_new_sale(self):
        """
            Fonction qui permet de créer une vente à partir de la CRM
        """
        sale_obj = self.env['sale.order']
        state = self.env['crm.state'].search(
            [('is_sale_creation_state', '=', True)], limit=1)
        for crm in self:
            if crm.customer_id:
                if crm.customer_id.state != 'qualified':
                    raise except_orm(
                        _('Error'),
                        _('You can\'t create a sale with a customer not qualified'
                          ))
                else:
                    new_sale = sale_obj.create_sale(self.customer_id.id, False,
                                                    fields.Date.today(),
                                                    {'crm_id': crm.id})
                    if state:
                        crm.write({'state_id': state.id})

                    action_dict = get_form_view(self,
                                                'sale.sale_order_see_form')
                    if action_dict and action_dict.get(
                            'id') and action_dict.get('type'):
                        action = self.env[action_dict['type']].browse(
                            action_dict['id'])
                        action_struc = action.read()
                        action_struc[0]['res_id'] = new_sale.id
                        action_struc = action_struc[0]
                        return action_struc

            return True
    def show_non_conformity_lines(self):
        """
            Fonction qui cherche et retourne les fiches de non conformités du partenaire et de la période sélectionnés
        """
        action_struc = dict()
        nonconformity_file_obj = self.env['nonconformity.file']

        if not (self.customer_id and self.date_from and self.date_to):
            return action_struc

        non_conformity_ids = nonconformity_file_obj.search([
            ('partner_id', '=', self.customer_id.id),
            ('create_date', '>=', self.date_from),
            ('create_date', '<=', self.date_to)
        ]).ids

        action_dict = get_form_view(self, 'stock.act_nonconformity_file_reception_id')

        if 'id' and 'type' in action_dict:
            action = self.env[action_dict['type']].browse(action_dict['id'])
            action_struc = action.read()
            action_struc[0]['domain'] = [('id', 'in', non_conformity_ids)]
            action_struc[0]['context'] = {}
            action_struc = action_struc[0]

        return action_struc
    def create_new_version(self):
        """
            Fonction permettant d'appeler la fonction de création de la nouvelle
            version et de renvoyer sur la vue de cette version
        """
        context = self.env.context
        if context.get('active_id', False) and self.version:
            document = self.env['document.openprod'].browse(
                context['active_id'])
            if document:
                new_version_id = document.create_new_version(self.version)
                if new_version_id:
                    action_dict = get_form_view(
                        self, 'base_openprod.document_openprod_see_form')
                    if action_dict and action_dict.get(
                            'id') and action_dict.get('type'):
                        action = self.env[action_dict['type']].browse(
                            action_dict['id'])
                        action_struc = action.read()
                        action_struc[0]['res_id'] = new_version_id.id
                        action_struc = action_struc[0]

                    return action_struc
                else:
                    return {'type': 'ir.actions.act_window_close'}
        else:
            return {'type': 'ir.actions.act_window_close'}
Exemple #5
0
 def create_transfer(self):
     for wizard in self:
         if wizard.label_ids:
             uom_qty = sum([l.uom_qty for l in wizard.label_ids])
         else:
             uom_qty = wizard.uom_qty
             
         transfer_rc = self.env['stock.transfer.request'].create({
             'product_id': wizard.product_id.id,
             'origin': 'Wizard',
             'warehouse_id': wizard.warehouse_id.id,
             'warehouse_dest_id': wizard.warehouse_dest_id.id,
             'uom_qty': uom_qty,
             'uom_id': wizard.product_id.uom_id.id,
             'needed_uom_qty': uom_qty,
             'needed_uom_id': wizard.product_id.uom_id.id,
             'need_date': wizard.date,
             'is_automatic': wizard.is_automatic,
             'departure_date': wizard.date,
             'is_billable': wizard.is_billable,
             'partner_id': wizard.partner_id.id,
             'price': wizard.price,
             'label_ids': [(6, 0, wizard.label_ids.ids)],
         })
         transfer_rc.create_transfer_picking_button()
         if wizard.make_done:
             for out_move_rc in transfer_rc.out_move_ids:
                 if out_move_rc.picking_id:
                     out_move_rc.picking_id.do_partial_auto()
         
     return get_form_view(self, 'stock.act_stock_transfer_request', res_id=transfer_rc.id, view_mode='form', target='current')
    def show_sale_order_lines(self):
        """
            Fonction retourne les lignes d'achat (retard ou non selon le context) du fournisseur et de la période
            sélectionnés
        """
        sale_order_line_rs = self._get_sale_order_line_rs()
        sale_order_line_ids = list()
        action_struc = dict()

        if not sale_order_line_rs:
            return action_struc

        if self.env.context.get('only_late_line'):
            sale_order_line_ids = self._get_late_sale_order_line_ids(sale_order_line_rs=sale_order_line_rs)
        else:
            sale_order_line_ids = sale_order_line_rs.ids

        action_dict = get_form_view(self, 'sale.action_sale_order_line')
        if action_dict and 'id' and 'type' in action_dict:
            action = self.env[action_dict['type']].browse(action_dict['id'])
            action_struc = action.read()
            action_struc[0]['domain'] = [('id', 'in', sale_order_line_ids)]
            action_struc[0]['context'] = {}
            action_struc = action_struc[0]
        return action_struc
 def create_new_sale(self):
     """
         Fonction qui permet de vérifier si le produit est actif et a un référencement client
         qui correspond au client de l'offre et qui envoie le wizard de création d evente
     """
     customerinfo_obj = self.env['product.customerinfo']
     for offer in self:
         product_rs = offer.product_id
         partner_rs = offer.partner_id
         if product_rs and partner_rs:
             #On recherche un référencement client correspondant au produit et au client de l'offre
             customer_ref = customerinfo_obj.search([('partner_id', '=', partner_rs.id), 
                                                     ('product_id', '=', product_rs.id), 
                                                     ('state', '=', 'active')], limit=1)
             if not product_rs.state in ['lifeserie', 'endlife'] or not customer_ref:
                 raise Warning(_('To create a sale, your product must be in life or end of life, and he must have '
                               'an active customer referencing with the customer of the offer'))
             else:
                 action_dict = get_form_view(self, 'specific_offer.action_create_sale_from_offer')
                 if action_dict and action_dict.get('id') and action_dict.get('type'):
                     action = self.env[action_dict['type']].browse(action_dict['id'])
                     action_struc = action.read()[0]
                     return action_struc
         else:
             return {'type': 'ir.actions.act_window_close'}
 def create_quick_purchase(self):
     """
         Fonction permettant de créer rapidement un achat
     """
     action_struc = {}
     if self.product_id and self.partner_id:
         other_data = {}
         po_line = {self.product_id: {'uom_qty': self.quantity, 'uom_id': self.uom_id.id}}
         if self.env.context.get('affair_id'):
             po_line[self.product_id]['affair_id'] = self.env.context.get('affair_id')
         other_data.update(self.env.context.get('quick_purchase_other_data_order', {}))
         new_purchase = self.env['purchase.order'].create_purchase(self.partner_id, po_line, self.date, other_data, 'uom_qty')
         #Lien avec les actions. Si on retrouve l'id d'une action dans le context et que l'action n'est pas
         #liée à un objet, on la lie avec l'achat
         context = self.env.context
         if context.get('active_id'):
             if context.get('active_model') == 'calendar.event':
                 action = self.env['calendar.event'].browse(context['active_id'])
                 if action and not action.purchase_id:
                     action.write({'purchase_id': new_purchase.id})
             elif context.get('active_model') == 'stock.transfer.request':
                 action = self.env['stock.transfer.request'].browse(context['active_id']).wkf_cancel()
                 
         #Point d'entree pour la GMAO/SAV
         self.write_intervention(new_purchase)
         
     action_dict = get_form_view(self, 'purchase.purchase_order_see_form')
     if action_dict and action_dict.get('id') and action_dict.get('type'):
         action = self.env[action_dict['type']].browse(action_dict['id'])
         action_struc = action.read()
         action_struc[0]['res_id'] = new_purchase.id
         action_struc = action_struc[0]
           
     return action_struc
 def create_quick_sale(self):
     """
         Fonction permettant de créer rapidement une vente
     """
     action_struc = {}
     if self.product_id and self.partner_id:
         other_data = {}
         so_line = {self.product_id: {'sec_uom_qty': self.quantity}}
         so_line[self.product_id].update(self.env.context.get('create_quick_sale_other_data', {}))
         other_data.update(self.env.context.get('quick_sale_other_data_order', {}))
         new_sale = self.env['sale.order'].create_sale(self.partner_id, so_line, self.date, other_data)
         #Lien avec les actions. Si on retrouve l'id d'une action dans le context et que l'action n'est pas
         #liée à un objet, on la lie avec la vente
         context = self.env.context
         if context.get('active_model') == 'calendar.event' and context.get('active_id'):
             action = self.env['calendar.event'].browse(context['active_id'])
             if action and not action.sale_id:
                 action.write({'sale_id': new_sale.id})
     
     action_dict = get_form_view(self, 'sale.sale_order_see_form')
     if action_dict and action_dict.get('id') and action_dict.get('type'):
         action = self.env[action_dict['type']].browse(action_dict['id'])
         action_struc = action.read()
         action_struc[0]['res_id'] = new_sale.id
         action_struc = action_struc[0]
           
     return action_struc
    def show_non_conformity_line(self):
        """
            Fonction qui cherche et retourne les fiches de non conformités du partenaire et de la période sélectionnés
        """
        supplier = self.supplier_id
        date_from = self.date_from
        date_to = self.date_to
        non_conformity_ids = []
        if supplier and date_from and date_to:
            non_conformity_ids = self.env['nonconformity.file'].search([
                ('partner_id', '=', supplier.id),
                ('create_date', '>=', self.date_from),
                ('create_date', '<=', date_to)
            ]).ids

        action_struc = {}
        action_dict = get_form_view(
            self, 'stock.act_nonconformity_file_reception_id')
        if action_dict and action_dict.get('id') and action_dict.get('type'):
            action = self.env[action_dict['type']].browse(action_dict['id'])
            action_struc = action.read()
            action_struc[0]['domain'] = [('id', 'in', non_conformity_ids)]
            action_struc[0]['context'] = {}
            action_struc = action_struc[0]

        return action_struc
 def create_new_opportunity(self):
     """
         Fonction qui permet de créer une opportunité à partir d'une action
     """
     crm_obj = self.env['crm']
     crm_state_obj = self.env['crm.state']
     data_obj = self.env['ir.model.data']
     for action in self:
         object_model, object_id = data_obj.get_object_reference(
             'crm_openprod', 'crm_state_new')
         if object_model and object_model == 'crm.state':
             state = crm_state_obj.browse(object_id)
             if state:
                 new_opportunity = crm_obj.create({
                     'description':
                     action.description,
                     'criticality':
                     'normal',
                     'state_id':
                     state.id,
                     'salesman_id':
                     self.env.user.id
                 })
                 if new_opportunity:
                     action.write({'crm_id': new_opportunity.id})
                     action_dict = get_form_view(
                         self, 'crm_openprod.act_crm_view_only_form')
                     if action_dict and action_dict.get(
                             'id') and action_dict.get('type'):
                         action = self.env[action_dict['type']].browse(
                             action_dict['id'])
                         action_struc = action.read()
                         action_struc[0]['res_id'] = new_opportunity.id
                         action_struc = action_struc[0]
                         return action_struc
Exemple #12
0
    def new_version(self):
        """
            Crée une nouvelle version du Workflow: Copie du workflow actuel
        """
        new_rs = self.env['workflow']
        transition_obj = self.env['workflow.transition']
        for wkf in self:
            name = wkf.name
            wkf.write({'versioning_date': fields.Datetime.now(),
                        'is_active': False,
                        'name': '%s (%s)'%(name, wkf.version)})
            new_rs = self.create({'is_active': True,
                                  'name': name,
                                  'osv': wkf.osv,
                                  'version': wkf.version + 1,
                                  'on_create': wkf.on_create})
            acivities_rs = wkf.activities
            acivities_ids = acivities_rs.ids
            act_map_dict = {}
            for act_rs in acivities_rs:
                act_map_dict[act_rs.id] = act_rs.copy({'wkf_id': new_rs.id}).id
                
            for act_rs in wkf.display_state_ids:
                act_rs.copy({'wkf_id': new_rs.id})

            # Map entre anciennes et nouvelles transitions
            for transition_rs in transition_obj.search(['|', ('act_from', 'in', acivities_ids), ('act_to', 'in', acivities_ids)]):
                transition_rs.copy({'act_from': act_map_dict[transition_rs.act_from.id],
                                    'act_to': act_map_dict[transition_rs.act_to.id]})
        
        return get_form_view(self, 'base.action_workflow_form', new_rs.id, 'form,tree,diagram')
    def create_new_offer(self):
        """
            Fonction qui permet de créer une offre à partir d'une opportunité
        """
        spec_offer_obj = self.env['specific.offer']
        state = self.env['crm.state'].search(
            [('is_offer_creation_state', '=', True)], limit=1)
        for crm in self:
            description = ''
            if crm.description:
                parser = myhtmlparser()
                parser.feed(crm.description)
                data = parser.HTMLDATA
                parser.clean()
                for text in data:
                    description += text + ' '

            new_offer = spec_offer_obj.create({
                'name': crm.name,
                'description': description,
                'partner_id': crm.customer_id.id,
                'crm_id': crm.id
            })
            if new_offer and state:
                crm.write({'state_id': state.id})
                action_dict = get_form_view(
                    self, 'specific_offer.act_specific_offer_view_only_form')
                if action_dict and action_dict.get('id') and action_dict.get(
                        'type'):
                    action = self.env[action_dict['type']].browse(
                        action_dict['id'])
                    action_struc = action.read()
                    action_struc[0]['res_id'] = new_offer.id
                    action_struc = action_struc[0]
                    return action_struc
    def switch_document_version(self):
        """
            Fonction permettant d'appeler la fonction de création d'un nouveau document et
            d'afficher ce nouveau document
        """
        context = self.env.context
        datas = {}
        if context.get('active_id', False) and self.version:
            document = self.env['document.openprod'].browse(
                context['active_id'])
            if document:
                #On récupère les valeurs des M2M
                for field in self._columns:
                    if isinstance(self._columns[field], f.many2many):
                        datas[field] = self[field]

                new_document_id = document.create_new_document(
                    datas, self.version)
                if new_document_id:
                    action_dict = get_form_view(
                        self, 'base_openprod.document_openprod_see_form')
                    if action_dict and action_dict.get(
                            'id') and action_dict.get('type'):
                        action = self.env[action_dict['type']].browse(
                            action_dict['id'])
                        action_struc = action.read()
                        action_struc[0]['res_id'] = new_document_id.id
                        action_struc = action_struc[0]

                    return action_struc
                else:
                    return {'type': 'ir.actions.act_window_close'}
        else:
            return {'type': 'ir.actions.act_window_close'}
    def visualization(self):
        """
            Création d'un move label avec son étiquette en draft
        """
        wizard_line_obj = self.env['create.label.wizard.line']
        wizard_line_rs = self.env['create.label.wizard.line']
        label_obj = self.env['stock.label']
        lot_obj = self.env['stock.lot']
        if self.new_auto_lot:
            vals = {'product_id': self.product_id.id}
            if self.supplier_lot_number:
                vals['supplier_lot_number'] = self.supplier_lot_number
            
            if self.expiry_date:
                vals['expiry_date'] = self.expiry_date

            if self.removal_date:
                vals['removal_date'] = self.removal_date
            
            lot_rs = lot_obj.create(vals)
        else:
            lot_rs = self.lot_id
            
        number_of_label = self.number_of_label
        while number_of_label:
            label_vals = {
                'template_id': self.label_template_id.id,
                'lot_id': lot_rs and lot_rs.id or False,
                'product_id': self.product_id.id,
                'uom_id': self.product_id.uom_id.id,
                'sec_uom_id': self.sec_uom_id.id,
                'is_variable_double_unit': self.is_variable_double_unit,
                'uom_qty': 0.0,
                'sec_uom_qty': 0.0,
            }
            if self.label_template_id.generate_label_in_advance:
                label_vals.update({
                    'name': self.label_template_id.sequence_id.next_by_id(),
                    'printed_qty': self.uom_qty,
                    'location_id': self.move_id.location_dest_id.id,
                })
                
            label_rc = label_obj.create(label_vals)
            wizard_line_rs |= wizard_line_obj.create({
                'wizard_id': self.id,
                'product_id': self.product_id.id,
                'uom_qty': self.uom_qty,
                'sec_uom_qty': self.sec_uom_qty,
                'label_id': label_rc.id,
                'uom_id': self.product_id.uom_id.id,
                'sec_uom_id': self.sec_uom_id.id or self.move_id.sec_uom_id.id,
                'is_variable_double_unit': self.is_variable_double_unit,
                'generate_label_in_advance': self.label_template_id.generate_label_in_advance,
            })
            number_of_label -= 1
            
        return get_form_view(self, 'stock.act_create_label_wizard', res_id=self.id, view_mode='form', target='new')
Exemple #16
0
    def action_stagger_purchase_delivery(self):
        """
            Fonction permettant de modifier le fournisseur d'un achat
        """
        for wizard in self:
            #On vérifie que la quantité entrée est inférieure à la quantité de la ligne
            #d'achat
            purchase_line = wizard.purchase_line_id
            price_unit = purchase_line.price_unit
            if wizard.quantity <= 0:
                raise except_orm(_("Error"),
                                 _('You must enter a quantity superior to 0'))

            if wizard.quantity >= purchase_line.sec_uom_qty:
                raise except_orm(
                    _("Error"),
                    _('You must enter a quantity inferior to the initial purchase '
                      'line quantity'))

            #On récupère les valeurs entrées dans le wizard
            values = {
                'sec_uom_qty': wizard.quantity,
                'expected_date': wizard.new_date
            }
            new_line = purchase_line.copy(values)
            new_line._onchange_sec_uom_qty(with_warning=False)
            new_line._onchange_uom_qty()
            new_line._onchange_uoi_qty()
            new_line.write({'price_unit': price_unit})
            #On décrémente la ligne initiale de la quantité de la nouvelle ligne (car celle-ci respecte forcément
            #le multiple et le minimum
            purchase_line.write(
                {'sec_uom_qty': purchase_line.sec_uom_qty - wizard.quantity})
            purchase_line._onchange_sec_uom_qty(with_warning=False)
            purchase_line._onchange_uom_qty()
            purchase_line._onchange_uoi_qty()
            purchase_line.write({'price_unit': price_unit})
            #On retourne l'achat
            if wizard.purchase_id:
                action_dict = get_form_view(
                    self, 'purchase.purchase_order_see_form')
                if action_dict and action_dict.get('id') and action_dict.get(
                        'type'):
                    action = self.env[action_dict['type']].browse(
                        action_dict['id'])
                    action_struc = action.read()
                    action_struc[0]['res_id'] = wizard.purchase_id.id
                    action_struc = action_struc[0]

                return action_struc
            else:
                return {'type': 'ir.actions.act_window_close'}
Exemple #17
0
    def show_partner_wo(self):
        """
            Fonction qui cherche et retourne les OT du partenaire
        """
        action_struc = {}
        action_dict = get_form_view(self, 'mrp.action_see_all_workorder')
        if action_dict and action_dict.get('id') and action_dict.get('type'):
            action = self.env[action_dict['type']].browse(action_dict['id'])
            action_struc = action.read()
            action_struc[0]['context'] = {'customer_id': self.id}
            action_struc = action_struc[0]

        return action_struc
Exemple #18
0
 def show_call_tender_answer(self):
     """
         Fonction qui cherche et retourne les pickings de l'achat
     """
     action_struc = {}
     action_dict = get_form_view(self, 'call_tender.act_tender_answer')
     tender_id = self.id
     if action_dict and action_dict.get('id') and action_dict.get('type'):
         action = self.env[action_dict['type']].browse(action_dict['id'])
         action_struc = action.read()
         action_struc[0]['domain'] = [('tender_id', '=', tender_id)]
         action_struc = action_struc[0]
           
     return action_struc
Exemple #19
0
    def update_product_id(self):
        """
            Fonction qui met à jour la vue pour un autre produit
        """
        action_struc = {}
        action_dict = get_form_view(
            self, 'sale_purchase.action_display_reservation')
        product_id = self.product_id.id
        if action_dict and action_dict.get('id') and action_dict.get('type'):
            action = self.env[action_dict['type']].browse(action_dict['id'])
            action_struc = action.read()
            action_struc[0]['context'] = {'reservation_product_id': product_id}
            action_struc = action_struc[0]

        return action_struc
 def show_affair_from_document(self):
     """
         Fonction qui cherche et retourne les affaires liées à ce document
     """
     action_struc = {}
     for document in self:
         action_dict = get_form_view(self, 'affair.action_see_all_affair')
         affair_ids = document.find_affair_ids()
         affair_ids = list(set(affair_ids))
         if action_dict and action_dict.get('id') and action_dict.get('type'):
             action = self.env[action_dict['type']].browse(action_dict['id'])
             action_struc = action.read()
             action_struc[0]['domain'] = [('id', 'in', affair_ids)]
             action_struc = action_struc[0]
           
     return action_struc
 def show_crm_from_document(self):
     """
         Fonction qui cherche et retourne les enregistrements de CRM liés à ce document
     """
     action_struc = {}
     for document in self:
         action_dict = get_form_view(self, 'crm_openprod.action_see_all_crm')
         crm_ids = document.find_crm_ids()
         crm_ids = list(set(crm_ids))
         if action_dict and action_dict.get('id') and action_dict.get('type'):
             action = self.env[action_dict['type']].browse(action_dict['id'])
             action_struc = action.read()
             action_struc[0]['domain'] = [('id', 'in', crm_ids)]
             action_struc = action_struc[0]
           
     return action_struc
Exemple #22
0
    def show_partner_refund(self):
        """
            Fonction qui cherche et retourne les avoirs et notes de crédit du partenaire
        """
        action_struc = {}
        action_dict = get_form_view(
            self, 'account_openprod.action_see_all_invoices')
        if action_dict and action_dict.get('id') and action_dict.get('type'):
            action = self.env[action_dict['type']].browse(action_dict['id'])
            action_struc = action.read()
            action_struc[0]['context'] = {
                'partner_id': self.id,
                'type': ('out_refund', 'in_refund')
            }
            action_struc = action_struc[0]

        return action_struc
Exemple #23
0
    def show_customer_invoice(self):
        """
            Fonction qui cherche et retourne les factures pour un contract de maintenance client
        """
        for maintenance_contract in self:
            action_struc = {}
            action_dict = get_form_view(self, 'sale.sale_invoice_action')
            invoice_ids = [x.id for x in maintenance_contract.invoice_ids]
            if action_dict and action_dict.get('id') and action_dict.get(
                    'type'):
                action = self.env[action_dict['type']].browse(
                    action_dict['id'])
                action_struc = action.read()
                action_struc[0]['context'] = {'invoice_ids': invoice_ids}
                action_struc = action_struc[0]

        return action_struc
    def show_program_lines(self):
        """
            Fonction associée au bouton qui renvoie vers la vue tree des lignes de programme
        """
        action_struc = {}
        action_dict = get_form_view(
            self,
            'master_production_schedule.master_production_schedule_line_see_tree'
        )
        if action_dict and action_dict.get('id') and action_dict.get('type'):
            action = self.env[action_dict['type']].browse(action_dict['id'])
            action_struc = action.read()
            action_struc[0]['domain'] = [('master_production_id', '=', self.id)
                                         ]
            action_struc = action_struc[0]

        return action_struc
 def action_change_purchase_supplier(self):
     """
         Fonction permettant de modifier le fournisseur d'un achat
     """
     for wizard in self:
         new_vals = {}
         property_ids = False
         purchase_line_rs = wizard.purchase_line_id
         #On passe l'origine du wizard dans la nouvelle commande d'achat
         other_data = {'source_document': wizard.origin}
         #Si le produit est en achat libre on récupère le fournisseur sélectionné
         if wizard.free_purchase:
             partner = wizard.new_supplier_id
         #Si le produit n'est pas en achat libre, on récupère le fournisseur du référencement
         #fournisseur sélectionné
         else:
             partner = wizard.new_supplierinfo_id.partner_id
             if wizard.new_supplierinfo_id.property_ids:
                 property_ids = wizard.new_supplierinfo_id.property_ids.ids
         
         #Création de l'achat
         new_purchase = self.env['purchase.order'].create_purchase(partner.id, False, wizard.need_date, other_data)
         #Modification de la ligne d'achat et appel des onchanges
         new_vals['property_ids'] = property_ids
         new_vals['purchase_order_id'] = new_purchase.id
         res = purchase_line_rs.onchange_product_id(product_id=purchase_line_rs.product_id, purchase_order=new_purchase,
                                              send_quantity=wizard.actual_qty, force_qty=True)
         new_vals.update(utils.transform_to_ids(purchase_line_rs, res))
         purchase_line_rs.write(new_vals)
         purchase_line_rs._onchange_sec_uom_qty(with_warning=False)
         #Suppression de l'achat s'il n'y a plus de ligne
         if not wizard.purchase_id.purchase_order_line_ids:
             wizard.purchase_id.unlink()
         
         #On retourne le nouvel achat créé
         if new_purchase:
             action_dict = get_form_view(self, 'purchase.purchase_order_see_form')
             if action_dict and action_dict.get('id') and action_dict.get('type'):
                 action = self.env[action_dict['type']].browse(action_dict['id'])
                 action_struc = action.read()
                 action_struc[0]['res_id'] = new_purchase.id
                 action_struc = action_struc[0]
                   
             return action_struc
         else:
             return {'type': 'ir.actions.act_window_close'}
Exemple #26
0
    def show_routing_from_document(self):
        """
            Fonction qui cherche et retourne les gammes liées à ce document
        """
        action_struc = {}
        for document in self:
            action_dict = get_form_view(self, 'mrp.action_see_all_routing')
            routing_ids = document.find_routing_ids(return_line=False)
            routing_ids = list(set(routing_ids))
            if action_dict and action_dict.get('id') and action_dict.get(
                    'type'):
                action = self.env[action_dict['type']].browse(
                    action_dict['id'])
                action_struc = action.read()
                action_struc[0]['domain'] = [('id', 'in', routing_ids)]
                action_struc = action_struc[0]

        return action_struc
    def show_product_from_document(self):
        """
            Fonction qui cherche et retourne les produits liés à ce document
        """
        action_struc = {}
        for document in self:
            action_dict = get_form_view(self, 'product.action_see_all_product')
            product_ids = document.find_product_ids()
            product_ids = list(set(product_ids))
            if action_dict and action_dict.get('id') and action_dict.get(
                    'type'):
                action = self.env[action_dict['type']].browse(
                    action_dict['id'])
                action_struc = action.read()
                action_struc[0]['domain'] = [('id', 'in', product_ids)]
                action_struc = action_struc[0]

        return action_struc
Exemple #28
0
    def show_wo_from_document(self):
        """
            Fonction qui cherche et retourne les OT liés à ce document
        """
        action_struc = {}
        for document in self:
            action_dict = get_form_view(self, 'mrp.action_see_all_workorder')
            wo_ids = document.find_workorder_ids()
            wo_ids = list(set(wo_ids))
            if action_dict and action_dict.get('id') and action_dict.get(
                    'type'):
                action = self.env[action_dict['type']].browse(
                    action_dict['id'])
                action_struc = action.read()
                action_struc[0]['domain'] = [('id', 'in', wo_ids)]
                action_struc = action_struc[0]

        return action_struc
    def show_purchase_line(self):
        """
            Fonction qui cherche et retourne les lignes d'achat (retard ou non) du fournisseur et de la période
            sélectionnés
        """
        purchase_line_obj = self.env['purchase.order.line']
        supplier = self.supplier_id
        date_from = self.date_from
        date_to = self.date_to
        purchase_line_ids = []
        context = self.env.context
        today = fields.Date.today()
        if supplier and date_from and date_to:
            args = [('purchase_partner_id', '=', supplier.id),
                    ('purchase_state', 'not in', ['draft', 'cancel']),
                    ('expected_date', '>=', date_from),
                    ('expected_date', '<=', date_to)]
            purchase_line_rs = purchase_line_obj.search(args)
            if context.get('search_late_line'):
                for purchase_line in purchase_line_rs:
                    compare_date = purchase_line.confirmed_date or purchase_line.last_delivery_date or False
                    if not compare_date:
                        compare_date = today

                    expected_date = purchase_line.expected_date
                    if compare_date and expected_date < compare_date:
                        purchase_line_ids.append(purchase_line.id)

            else:
                purchase_line_ids = purchase_line_rs.ids

        action_struc = {}
        action_dict = get_form_view(self,
                                    'purchase.action_purchase_order_line')
        if action_dict and action_dict.get('id') and action_dict.get('type'):
            action = self.env[action_dict['type']].browse(action_dict['id'])
            action_struc = action.read()
            action_struc[0]['domain'] = [('id', 'in', purchase_line_ids)]
            action_struc[0]['context'] = {}
            action_struc = action_struc[0]

        return action_struc
Exemple #30
0
    def show_customer_line_invoice_line(self):
        """
            Fonction qui cherche et retourne les lignes de facture de la ligne de vente
        """
        for maintenance_contract in self:
            action_struc = {}
            action_dict = get_form_view(self, 'sale.sale_line_invoice_action')
            line_rcs = self.env['account.invoice.line'].search([
                ('maintenance_contract_id', '=', maintenance_contract.id)
            ])
            line_ids = line_rcs and line_rcs.ids or []
            if action_dict and action_dict.get('id') and action_dict.get(
                    'type'):
                action = self.env[action_dict['type']].browse(
                    action_dict['id'])
                action_struc = action.read()
                action_struc[0]['context'] = {'invoice_ids': line_ids}
                action_struc = action_struc[0]

        return action_struc