mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 13:32:03 +02:00
Initial commit: Sale packages
This commit is contained in:
commit
14e3d26998
6469 changed files with 2479670 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import crm_opportunity_to_quotation
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class Opportunity2Quotation(models.TransientModel):
|
||||
_name = 'crm.quotation.partner'
|
||||
_description = 'Create new or use existing Customer on new Quotation'
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
result = super(Opportunity2Quotation, self).default_get(fields)
|
||||
|
||||
active_model = self._context.get('active_model')
|
||||
if active_model != 'crm.lead':
|
||||
raise UserError(_('You can only apply this action from a lead.'))
|
||||
|
||||
lead = False
|
||||
if result.get('lead_id'):
|
||||
lead = self.env['crm.lead'].browse(result['lead_id'])
|
||||
elif 'lead_id' in fields and self._context.get('active_id'):
|
||||
lead = self.env['crm.lead'].browse(self._context['active_id'])
|
||||
if lead:
|
||||
result['lead_id'] = lead.id
|
||||
partner_id = result.get('partner_id') or lead._find_matching_partner().id
|
||||
if 'action' in fields and not result.get('action'):
|
||||
result['action'] = 'exist' if partner_id else 'create'
|
||||
if 'partner_id' in fields and not result.get('partner_id'):
|
||||
result['partner_id'] = partner_id
|
||||
|
||||
return result
|
||||
|
||||
action = fields.Selection([
|
||||
('create', 'Create a new customer'),
|
||||
('exist', 'Link to an existing customer'),
|
||||
('nothing', 'Do not link to a customer')
|
||||
], string='Quotation Customer', required=True)
|
||||
lead_id = fields.Many2one('crm.lead', "Associated Lead", required=True)
|
||||
partner_id = fields.Many2one('res.partner', 'Customer')
|
||||
|
||||
def action_apply(self):
|
||||
""" Convert lead to opportunity or merge lead and opportunity and open
|
||||
the freshly created opportunity view.
|
||||
"""
|
||||
self.ensure_one()
|
||||
if self.action == 'create':
|
||||
self.lead_id._handle_partner_assignment(create_missing=True)
|
||||
elif self.action == 'exist':
|
||||
self.lead_id._handle_partner_assignment(force_partner_id=self.partner_id.id, create_missing=False)
|
||||
return self.lead_id.action_new_quotation()
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="crm_quotation_partner_view_form" model="ir.ui.view">
|
||||
<field name="name">crm.quotation.partner.view.form</field>
|
||||
<field name="model">crm.quotation.partner</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="New Quotation">
|
||||
<group>
|
||||
<group>
|
||||
<field name="action" widget="radio"/>
|
||||
<field name="lead_id" invisible="1"/>
|
||||
</group>
|
||||
</group>
|
||||
<group attrs="{'invisible': [('action','!=','exist')], 'required':[('action', '=','exist')]}">
|
||||
<group>
|
||||
<field name="partner_id" attrs="{'invisible': [('action','!=','exist')], 'required':[('action', '=','exist')]}"
|
||||
context="{'res_partner_search_mode': 'customer'}" />
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_apply" string="Confirm" type="object" class="btn-primary" data-hotkey="q"/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel" data-hotkey="z"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="crm_quotation_partner_action" model="ir.actions.act_window">
|
||||
<field name="name">New Quotation</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">crm.quotation.partner</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="crm_quotation_partner_view_form"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue