Add modules sale_from_private_stock and sale_order_add_bom

Port base_company_extension to v10
Avoid blockage on l10n_fr_infogreffe_connector
This commit is contained in:
Alexis de Lattre
2016-10-11 17:46:53 +02:00
parent 6907302f8e
commit d331dee3ba
7 changed files with 172 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from . import mrp_bom
from . import wizard

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Sale Order Add Bom',
'version': '9.0.1.0.0',
'category': 'Sales Management',
'license': 'AGPL-3',
'summary': 'Wizard to select a bom from a sale order',
'description': """
This module adds a wizard *Add Kit* on the form view of a quotation that allows the user to select a 'kit' BOM: Odoo will automatically add the components of the kit as sale order lines.
This module has been written by Alexis de Lattre from Akretion
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['sale', 'mrp'],
'data': [
'wizard/sale_add_phantom_bom_view.xml',
'sale_view.xml',
],
'installable': True,
}

View File

@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields
class MrpBom(models.Model):
_inherit = 'mrp.bom'
_rec_name = 'product_id'
sale_ok = fields.Boolean(related='product_id.sale_ok', store=True)

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<data>
<record id="view_order_form" model="ir.ui.view">
<field name="name">add.bom.sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<button name="action_quotation_send" position="before">
<button name="%(sale_add_phantom_bom_action)d" type="action"
string="Add Kit" states="draft,sent"/>
</button>
</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import sale_add_phantom_bom

View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api, _
from openerp.exceptions import UserError
from openerp.tools import float_is_zero
class SaleAddPhantomBom(models.TransientModel):
_name = 'sale.add.phantom.bom'
_description = 'Add Kit to Quotation'
@api.model
def _default_sale_id(self):
assert self._context.get('active_model') == 'sale.order'
return self.env['sale.order'].browse(self._context['active_id'])
bom_id = fields.Many2one(
'mrp.bom', 'Kit', required=True,
domain=[('type', '=', 'phantom'), ('sale_ok', '=', True)])
qty = fields.Integer(
string='Number of Kits to Add', default=1, required=True)
# I can 't put the sale_id fields required=True because
# it may block the deletion of a sale order
sale_id = fields.Many2one(
'sale.order', string='Quotation', default=_default_sale_id)
@api.model
def _prepare_sale_order_line(self, bom_line, sale_order, wizard_qty):
qty_in_product_uom = self.env['product.uom']._compute_qty_obj(
bom_line.product_uom,
bom_line.product_qty,
bom_line.product_id.uom_id)
vals = {
'product_id': bom_line.product_id.id,
'product_uom_qty': qty_in_product_uom * wizard_qty,
'order_id': sale_order.id,
}
return vals
@api.multi
def add(self):
self.ensure_one()
assert self.sale_id, 'No related sale_id'
if self.qty < 1:
raise UserError(_(
"The number of kits to add must be 1 or superior"))
assert self.bom_id.type == 'phantom', 'The BOM is not a kit'
if not self.bom_id.bom_line_ids:
raise UserError(_("The selected kit is empty !"))
prec = self.env['decimal.precision'].precision_get(
'Product Unit of Measure')
today = fields.Date.context_today(self)
solo = self.env['sale.order.line']
for line in self.bom_id.bom_line_ids:
if float_is_zero(line.product_qty, precision_digits=prec):
continue
if line.date_start and line.date_start > today:
continue
if line.date_stop and line.date_stop < today:
continue
# The onchange is played in the inherit of the create()
# of sale order line in the 'sale' module
# TODO: if needed, we could increment existing order lines
# with the same product instead of always creating new lines
vals = self._prepare_sale_order_line(line, self.sale_id, self.qty)
solo.create(vals)
return True

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<data>
<record id="sale_add_phantom_bom_form" model="ir.ui.view">
<field name="name">sale.add.phantom.bom.form</field>
<field name="model">sale.add.phantom.bom</field>
<field name="arch" type="xml">
<form string="Add Phantom BOM to the Quotation">
<group name="main">
<field name="bom_id"/>
<field name="qty"/>
</group>
<footer>
<button name="add" type="object"
class="oe_highlight" string="Add to Quotation"/>
<button special="cancel" string="Cancel" class="oe_link"/>
</footer>
</form>
</field>
</record>
<record id="sale_add_phantom_bom_action" model="ir.actions.act_window">
<field name="name">Add Kit</field>
<field name="res_model">sale.add.phantom.bom</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</odoo>