diff --git a/addons/event_sale/__openerp__.py b/addons/event_sale/__openerp__.py
index ff65d0e9172..a0cd3521aa4 100644
--- a/addons/event_sale/__openerp__.py
+++ b/addons/event_sale/__openerp__.py
@@ -38,7 +38,7 @@ when you confirm your sale order it will automatically create a registration for
this event.
""",
'author': 'OpenERP SA',
- 'depends': ['event','sale','sale_crm'],
+ 'depends': ['event', 'sale_crm'],
'update_xml': [
'event_sale_view.xml',
],
diff --git a/addons/multi_company/__openerp__.py b/addons/multi_company/__openerp__.py
index c8e06b5cf2b..3550e304551 100644
--- a/addons/multi_company/__openerp__.py
+++ b/addons/multi_company/__openerp__.py
@@ -34,7 +34,7 @@ This module is the base module for other multi-company modules.
'website': 'http://www.openerp.com/',
'depends': [
'base',
- 'sale',
+ 'sale_stock',
'project',
],
'init_xml': [],
diff --git a/addons/portal_sale/__openerp__.py b/addons/portal_sale/__openerp__.py
index f87bebd19fd..c6a35d7c9e6 100644
--- a/addons/portal_sale/__openerp__.py
+++ b/addons/portal_sale/__openerp__.py
@@ -30,7 +30,7 @@ This module adds sale menu and features to your portal if sale and portal are
installed.
""",
'author': 'OpenERP SA',
- 'depends': ['sale','portal'],
+ 'depends': ['sale_stock','portal'],
'data': [
'security/portal_security.xml',
'portal_sale_view.xml',
diff --git a/addons/project_mrp/process/project_mrp_process.xml b/addons/project_mrp/process/project_mrp_process.xml
index 33d8698ce3d..729f107b755 100644
--- a/addons/project_mrp/process/project_mrp_process.xml
+++ b/addons/project_mrp/process/project_mrp_process.xml
@@ -51,7 +51,7 @@
-
+
diff --git a/addons/sale/__init__.py b/addons/sale/__init__.py
index fe19b7fa609..5a7b4b499df 100644
--- a/addons/sale/__init__.py
+++ b/addons/sale/__init__.py
@@ -24,11 +24,9 @@
#----------------------------------------------------------
import sale
-import stock
import res_partner
import wizard
import report
-import company
import edi
import res_config
diff --git a/addons/sale/__openerp__.py b/addons/sale/__openerp__.py
index f5bf1adb436..438137daa64 100644
--- a/addons/sale/__openerp__.py
+++ b/addons/sale/__openerp__.py
@@ -35,8 +35,6 @@ Workflow with validation steps:
Create Invoice:
---------------
- * Invoice on Demand
- * Invoice on Delivery Order
* Invoice Before Delivery
Partners preferences:
@@ -45,16 +43,6 @@ Partners preferences:
* Shipping
* Invoicing
-Products stocks and prices:
---------------------------
-
-Delivery method:
------------------
- * The Poste
- * Free Delivery Charges
- * Normal Delivery Charges
- * Based on the Delivery Order(if not Add to sale order)
-
Dashboard for Sales Manager that includes:
------------------------------------------
* My Quotations
@@ -63,15 +51,11 @@ Dashboard for Sales Manager that includes:
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'images': ['images/deliveries_to_invoice.jpeg','images/sale_dashboard.jpeg','images/Sale_order_line_to_invoice.jpeg','images/sale_order.jpeg','images/sales_analysis.jpeg'],
- 'depends': ['stock', 'procurement', 'board', 'account_voucher'],
+ 'depends': ['board', 'account_voucher'],
'init_xml': [],
- 'update_xml': [
- 'wizard/sale_make_invoice_advance.xml',
- 'wizard/sale_line_invoice.xml',
- 'wizard/sale_make_invoice.xml',
+ 'update_xml': ['wizard/sale_line_invoice.xml',
'security/sale_security.xml',
'security/ir.model.access.csv',
- 'company_view.xml',
'sale_workflow.xml',
'sale_sequence.xml',
'sale_report.xml',
@@ -79,7 +63,6 @@ Dashboard for Sales Manager that includes:
'sale_view.xml',
'res_partner_view.xml',
'report/sale_report_view.xml',
- 'stock_view.xml',
'process/sale_process.xml',
'board_sale_view.xml',
'edi/sale_order_action_data.xml',
@@ -88,8 +71,6 @@ Dashboard for Sales Manager that includes:
'demo_xml': ['sale_demo.xml'],
'test': [
'test/sale_order_demo.yml',
- 'test/picking_order_policy.yml',
- 'test/manual_order_policy.yml',
'test/prepaid_order_policy.yml',
'test/cancel_order.yml',
'test/delete_order.yml',
diff --git a/addons/sale/edi/sale_order.py b/addons/sale/edi/sale_order.py
index b850922cbb2..cbde0cc742a 100644
--- a/addons/sale/edi/sale_order.py
+++ b/addons/sale/edi/sale_order.py
@@ -185,16 +185,17 @@ class sale_order(osv.osv, EDIMixin):
order_lines = edi_document['order_line']
for order_line in order_lines:
- self._edi_requires_attributes(('date_planned', 'product_id', 'product_uom', 'product_qty', 'price_unit'), order_line)
+ self._edi_requires_attributes(( 'product_id', 'product_uom', 'product_qty', 'price_unit'), order_line)
order_line['product_uom_qty'] = order_line['product_qty']
del order_line['product_qty']
- date_planned = order_line.pop('date_planned')
- delay = 0
- if date_order and date_planned:
- # no security_days buffer, this is the promised date given by supplier
- delay = (datetime.strptime(date_planned, DEFAULT_SERVER_DATE_FORMAT) - \
- datetime.strptime(date_order, DEFAULT_SERVER_DATE_FORMAT)).days
- order_line['delay'] = delay
+ #Need to move sale_stock
+# date_planned = order_line.pop('date_planned')
+# delay = 0
+# if date_order and date_planned:
+# # no security_days buffer, this is the promised date given by supplier
+# delay = (datetime.strptime(date_planned, DEFAULT_SERVER_DATE_FORMAT) - \
+# datetime.strptime(date_order, DEFAULT_SERVER_DATE_FORMAT)).days
+# order_line['delay'] = delay
# discard web preview fields, if present
order_line.pop('price_subtotal', None)
@@ -218,9 +219,9 @@ class sale_order_line(osv.osv, EDIMixin):
# company.security_days is for internal use, so customer should only
# see the expected date_planned based on line.delay
- date_planned = datetime.strptime(line.order_id.date_order, DEFAULT_SERVER_DATE_FORMAT) + \
- relativedelta(days=line.delay or 0.0)
- edi_doc['date_planned'] = date_planned.strftime(DEFAULT_SERVER_DATE_FORMAT)
+# date_planned = datetime.strptime(line.order_id.date_order, DEFAULT_SERVER_DATE_FORMAT) + \
+# relativedelta(days=line.delay or 0.0)
+# edi_doc['date_planned'] = date_planned.strftime(DEFAULT_SERVER_DATE_FORMAT)
edi_doc_list.append(edi_doc)
return edi_doc_list
diff --git a/addons/sale/edi/sale_order_action_data.xml b/addons/sale/edi/sale_order_action_data.xml
index 2fe0a8cbfd3..4f1eb1c81cf 100644
--- a/addons/sale/edi/sale_order_action_data.xml
+++ b/addons/sale/edi/sale_order_action_data.xml
@@ -28,10 +28,10 @@
-
+
diff --git a/addons/sale/process/sale_process.xml b/addons/sale/process/sale_process.xml
index b688f2aeb7f..05999ff6fb8 100644
--- a/addons/sale/process/sale_process.xml
+++ b/addons/sale/process/sale_process.xml
@@ -28,18 +28,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -62,38 +50,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -142,54 +98,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -217,61 +125,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/addons/sale/report/sale_report.py b/addons/sale/report/sale_report.py
index 6beac7cfd38..0062ca4313c 100644
--- a/addons/sale/report/sale_report.py
+++ b/addons/sale/report/sale_report.py
@@ -30,8 +30,6 @@ class sale_report(osv.osv):
_columns = {
'date': fields.date('Date Order', readonly=True),
'date_confirm': fields.date('Date Confirm', readonly=True),
- 'shipped': fields.boolean('Shipped', readonly=True),
- 'shipped_qty_1': fields.integer('Shipped', readonly=True),
'year': fields.char('Year', size=4, readonly=True),
'month': fields.selection([('01', 'January'), ('02', 'February'), ('03', 'March'), ('04', 'April'),
('05', 'May'), ('06', 'June'), ('07', 'July'), ('08', 'August'), ('09', 'September'),
@@ -54,7 +52,6 @@ class sale_report(osv.osv):
('waiting_date', 'Waiting Schedule'),
('manual', 'Manual In Progress'),
('progress', 'In Progress'),
- ('shipping_except', 'Shipping Exception'),
('invoice_except', 'Invoice Exception'),
('done', 'Done'),
('cancel', 'Cancelled')
@@ -86,8 +83,6 @@ class sale_report(osv.osv):
extract(epoch from avg(date_trunc('day',s.date_confirm)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay,
s.state,
t.categ_id as categ_id,
- s.shipped,
- s.shipped::integer as shipped_qty_1,
s.pricelist_id as pricelist_id,
s.project_id as analytic_account_id
from
@@ -110,7 +105,6 @@ class sale_report(osv.osv):
s.shop_id,
s.company_id,
s.state,
- s.shipped,
s.pricelist_id,
s.project_id
)
diff --git a/addons/sale/report/sale_report_view.xml b/addons/sale/report/sale_report_view.xml
index 8eb4fc85ce6..d572a47b80f 100644
--- a/addons/sale/report/sale_report_view.xml
+++ b/addons/sale/report/sale_report_view.xml
@@ -21,7 +21,6 @@
-
diff --git a/addons/sale/res_config.py b/addons/sale/res_config.py
index 45c01c582a0..1b1d167578d 100644
--- a/addons/sale/res_config.py
+++ b/addons/sale/res_config.py
@@ -30,14 +30,6 @@ class sale_configuration(osv.osv_memory):
'group_invoice_so_lines': fields.boolean('Based on Sale Orders',
implied_group='sale.group_invoice_so_lines',
help="To allow your salesman to make invoices for sale order lines using the menu 'Lines to Invoice'."),
- 'group_invoice_deli_orders': fields.boolean('Based on Delivery Orders',
- implied_group='sale.group_invoice_deli_orders',
- help="To allow your salesman to make invoices for Delivery Orders using the menu 'Deliveries to Invoice'."),
- 'task_work': fields.boolean('Based on Task Activities',
- help="""Lets you transfer the entries under tasks defined for Project Management to
- the Timesheet line entries for particular date and particular user with the effect of creating, editing and deleting either ways
- and to automatically creates project tasks from procurement lines.
- This installs the modules project_timesheet and project_mrp."""),
'timesheet': fields.boolean('Based on Timesheet',
help = """For modifying account analytic view to show important data to project manager of services companies.
You can also view the report of account analytic summary user-wise as well as month wise.
@@ -49,16 +41,10 @@ class sale_configuration(osv.osv_memory):
You will be able to follow the progress of the contract and invoice automatically.
It installs the account_analytic_analysis module."""),
'default_order_policy': fields.selection(
- [('manual', 'Invoice Based on Sales Orders'), ('picking', 'Invoice Based on Deliveries')],
+ [('manual', 'Invoice Based on Sales Orders')],
'Default Method', default_model='sale.order',
- help="You can generate invoices based on sales orders or based on shippings."),
- 'module_delivery': fields.boolean('Allow Charging Shipping Costs',
- help ="""Allows you to add delivery methods in sale orders and delivery orders.
- You can define your own carrier and delivery grids for prices.
- This installs the module delivery."""),
+ help="You can generate invoices based on sales orders."),
'time_unit': fields.many2one('product.uom', 'Working Time Unit'),
- 'default_picking_policy' : fields.boolean("Configurable Shipping Policy",
- help = "You will be able to configure, per sale order, if you deliver all products at once or if you deliver each product when it is available. This may have an impact on the shipping price."),
'group_sale_pricelist':fields.boolean("Pricelist per Customer",
implied_group='product.group_sale_pricelist',
help="""Allows to manage different prices based on rules per category of customers.
@@ -69,15 +55,9 @@ class sale_configuration(osv.osv_memory):
'group_sale_delivery_address': fields.boolean("Allow Different Addresses for Delivery and Invoice",
implied_group='sale.group_delivery_invoice_address',
help="Allows you to specify different delivery and invoice addresses on a sale order."),
- 'group_mrp_properties': fields.boolean('Properties on Lines',
- implied_group='sale.group_mrp_properties',
- help="Allows you to tag sale order lines with properties."),
'group_discount_per_so_line': fields.boolean("Discount per Line",
implied_group='sale.group_discount_per_so_line',
help="Allows you to apply some discount per sale order line."),
- 'group_multiple_shops': fields.boolean("Manage Multiple Shops",
- implied_group='stock.group_locations',
- help="This allows to configure and use multiple shops."),
'module_warning': fields.boolean("Alerts by Products or Customers",
help="""Allow to configure warnings on products and trigger them when a user wants to sale a given product or a given customer.
Example: Product: this product is deprecated, do not purchase more than 5.
@@ -95,8 +75,6 @@ class sale_configuration(osv.osv_memory):
This is mostly used when a user encodes his timesheet. The values are retrieved and the fields are auto-filled.
But the possibility to change these values is still available.
This installs the module analytic_user_function."""),
- 'module_project_timesheet': fields.boolean("Project Timesheet"),
- 'module_project_mrp': fields.boolean("Project MRP"),
'module_project': fields.boolean("Project"),
'decimal_precision': fields.integer('Decimal Precision on Price',help="As an example, a decimal precision of 2 will allow prices like: 9.99 EUR, whereas a decimal precision of 4 will allow prices like: 0.0231 EUR per unit."),
}
@@ -113,8 +91,6 @@ class sale_configuration(osv.osv_memory):
def default_get(self, cr, uid, fields, context=None):
ir_model_data = self.pool.get('ir.model.data')
res = super(sale_configuration, self).default_get(cr, uid, fields, context)
- # task_work, time_unit depend on other fields
- res['task_work'] = res.get('module_project_mrp') and res.get('module_project_timesheet')
if res.get('module_project'):
user = self.pool.get('res.users').browse(cr, uid, uid, context)
res['time_unit'] = user.company_id.project_time_mode_id.id
@@ -123,13 +99,6 @@ class sale_configuration(osv.osv_memory):
res['time_unit'] = product.uom_id.id
return res
- def get_default_sale_config(self, cr, uid, ids, context=None):
- ir_values = self.pool.get('ir.values')
- default_picking_policy = ir_values.get_default(cr, uid, 'sale.order', 'picking_policy')
- return {
- 'default_picking_policy': default_picking_policy == 'one',
- }
-
def _get_default_time_unit(self, cr, uid, context=None):
ids = self.pool.get('product.uom').search(cr, uid, [('name', '=', _('Hour'))], context=context)
return ids and ids[0] or False
@@ -149,13 +118,9 @@ class sale_configuration(osv.osv_memory):
dp.write({'digits': config.decimal_precision})
def set_sale_defaults(self, cr, uid, ids, context=None):
- ir_values = self.pool.get('ir.values')
ir_model_data = self.pool.get('ir.model.data')
wizard = self.browse(cr, uid, ids)[0]
- default_picking_policy = 'one' if wizard.default_picking_policy else 'direct'
- ir_values.set_default(cr, uid, 'sale.order', 'picking_policy', default_picking_policy)
-
if wizard.time_unit:
product = ir_model_data.get_object(cr, uid, 'product', 'product_consultant')
product.write({'uom_id': wizard.time_unit.id, 'uom_po_id': wizard.time_unit.id})
@@ -166,11 +131,9 @@ class sale_configuration(osv.osv_memory):
return {}
- def onchange_invoice_methods(self, cr, uid, ids, group_invoice_so_lines, group_invoice_deli_orders, context=None):
- if not group_invoice_deli_orders:
+ def onchange_invoice_methods(self, cr, uid, ids, group_invoice_so_lines, context=None):
+ if group_invoice_so_lines:
return {'value': {'default_order_policy': 'manual'}}
- if not group_invoice_so_lines:
- return {'value': {'default_order_policy': 'picking'}}
return {}
def onchange_task_work(self, cr, uid, ids, task_work, context=None):
diff --git a/addons/sale/res_config_view.xml b/addons/sale/res_config_view.xml
index ee05a6d2d26..acd545122ce 100644
--- a/addons/sale/res_config_view.xml
+++ b/addons/sale/res_config_view.xml
@@ -9,29 +9,21 @@
-
-
-
-
-
-
-
-
-
+
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index f920b34ca42..a5316ce10fa 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -35,7 +35,6 @@ class sale_shop(osv.osv):
_columns = {
'name': fields.char('Shop Name', size=64, required=True),
'payment_default_id': fields.many2one('account.payment.term', 'Default Payment Term', required=True),
- 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse'),
'pricelist_id': fields.many2one('product.pricelist', 'Pricelist'),
'project_id': fields.many2one('account.analytic.account', 'Analytic Account', domain=[('parent_id', '!=', False)]),
'company_id': fields.many2one('res.company', 'Company', required=False),
@@ -50,16 +49,13 @@ class sale_order(osv.osv):
_name = "sale.order"
_inherit = ['ir.needaction_mixin', 'mail.thread']
_description = "Sales Order"
-
def copy(self, cr, uid, id, default=None, context=None):
if not default:
default = {}
default.update({
'state': 'draft',
- 'shipped': False,
'invoice_ids': [],
- 'picking_ids': [],
'date_confirm': False,
'name': self.pool.get('ir.sequence').get(cr, uid, 'sale.order'),
})
@@ -90,44 +86,6 @@ class sale_order(osv.osv):
res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
return res
- # This is False
- def _picked_rate(self, cr, uid, ids, name, arg, context=None):
- if not ids:
- return {}
- res = {}
- tmp = {}
- for id in ids:
- tmp[id] = {'picked': 0.0, 'total': 0.0}
- cr.execute('''SELECT
- p.sale_id as sale_order_id, sum(m.product_qty) as nbr, mp.state as procurement_state, m.state as move_state, p.type as picking_type
- FROM
- stock_move m
- LEFT JOIN
- stock_picking p on (p.id=m.picking_id)
- LEFT JOIN
- procurement_order mp on (mp.move_id=m.id)
- WHERE
- p.sale_id IN %s GROUP BY m.state, mp.state, p.sale_id, p.type''', (tuple(ids),))
-
- for item in cr.dictfetchall():
- if item['move_state'] == 'cancel':
- continue
-
- if item['picking_type'] == 'in':#this is a returned picking
- tmp[item['sale_order_id']]['total'] -= item['nbr'] or 0.0 # Deducting the return picking qty
- if item['procurement_state'] == 'done' or item['move_state'] == 'done':
- tmp[item['sale_order_id']]['picked'] -= item['nbr'] or 0.0
- else:
- tmp[item['sale_order_id']]['total'] += item['nbr'] or 0.0
- if item['procurement_state'] == 'done' or item['move_state'] == 'done':
- tmp[item['sale_order_id']]['picked'] += item['nbr'] or 0.0
-
- for order in self.browse(cr, uid, ids, context=context):
- if order.shipped:
- res[order.id] = 100.0
- else:
- res[order.id] = tmp[order.id]['total'] and (100.0 * tmp[order.id]['picked'] / tmp[order.id]['total']) or 0.0
- return res
def _invoiced_rate(self, cursor, user, ids, name, arg, context=None):
res = {}
@@ -208,11 +166,9 @@ class sale_order(osv.osv):
('cancel', 'Cancelled'),
('waiting_date', 'Waiting Schedule'),
('progress', 'Sale Order'),
- ('manual', 'Sale to Invoice'),
- ('shipping_except', 'Shipping Exception'),
('invoice_except', 'Invoice Exception'),
('done', 'Done'),
- ], 'Status', readonly=True, help="Gives the state of the quotation or sales order. \nThe exception state is automatically set when a cancel operation occurs in the invoice validation (Invoice Exception) or in the picking list process (Shipping Exception). \nThe 'Waiting Schedule' state is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
+ ], 'Status', readonly=True, help="Gives the state of the quotation or sales order. \nThe exception state is automatically set when a cancel operation occurs in the invoice validation (Invoice Exception). \nThe 'Waiting Schedule' state is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
'date_order': fields.date('Date', required=True, readonly=True, select=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'create_date': fields.datetime('Creation Date', readonly=True, select=True, help="Date on which sales order is created."),
'date_confirm': fields.date('Confirmation Date', readonly=True, select=True, help="Date on which sales order is confirmed."),
@@ -220,28 +176,16 @@ class sale_order(osv.osv):
'partner_id': fields.many2one('res.partner', 'Customer', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, required=True, change_default=True, select=True),
'partner_invoice_id': fields.many2one('res.partner', 'Invoice Address', readonly=True, required=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Invoice address for current sales order."),
'partner_shipping_id': fields.many2one('res.partner', 'Shipping Address', readonly=True, required=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Shipping address for current sales order."),
-
- 'incoterm': fields.many2one('stock.incoterms', 'Incoterm', help="Incoterm which stands for 'International Commercial terms' implies its a series of sales terms which are used in the commercial transaction."),
- 'picking_policy': fields.selection([('direct', 'Deliver each product when available'), ('one', 'Deliver all products at once')],
- 'Shipping Policy', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
- help="""If you don't have enough stock available to deliver all at once, do you accept partial shipments or not?"""),
'order_policy': fields.selection([
- ('manual', 'On Demand'),
- ('picking', 'On Delivery Order'),
('prepaid', 'Before Delivery'),
], 'Create Invoice', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
help="""This field controls how invoice and delivery operations are synchronized.
- - With 'On Demand', the invoice is created manually when needed.
- - With 'On Delivery Order', a draft invoice is generated after all pickings have been processed.
- With 'Before Delivery', a draft invoice is created, and it must be paid before delivery."""),
'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Pricelist for current sales order."),
'project_id': fields.many2one('account.analytic.account', 'Contract/Analytic Account', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="The analytic account related to a sales order."),
'order_line': fields.one2many('sale.order.line', 'order_id', 'Order Lines', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'invoice_ids': fields.many2many('account.invoice', 'sale_order_invoice_rel', 'order_id', 'invoice_id', 'Invoices', readonly=True, help="This is the list of invoices that have been generated for this sales order. The same sales order may have been invoiced in several times (by line for example)."),
- 'picking_ids': fields.one2many('stock.picking.out', 'sale_id', 'Related Picking', readonly=True, help="This is a list of delivery orders that has been generated for this sales order."),
- 'shipped': fields.boolean('Delivered', readonly=True, help="It indicates that the sales order has been delivered. This field is updated only after the scheduler(s) have been launched."),
- 'picked_rate': fields.function(_picked_rate, string='Picked', type='float'),
'invoiced_rate': fields.function(_invoiced_rate, string='Invoiced', type='float'),
'invoiced': fields.function(_invoiced, string='Paid',
fnct_search=_invoiced_search, type='boolean', help="It indicates that an invoice has been paid."),
@@ -266,15 +210,14 @@ class sale_order(osv.osv):
},
multi='sums', help="The total amount."),
- 'invoice_quantity': fields.selection([('order', 'Ordered Quantities'), ('procurement', 'Shipped Quantities')], 'Invoice on', help="The sale order will automatically create the invoice proposition (draft invoice). Ordered and delivered quantities may not be the same. You have to choose if you want your invoice based on ordered or shipped quantities. If the product is a service, shipped quantities means hours spent on the associated tasks.", required=True, readonly=True, states={'draft': [('readonly', False)]}),
+ 'invoice_quantity': fields.selection([('order', 'Ordered Quantities')], 'Invoice on', help="The sale order will automatically create the invoice proposition (draft invoice). Ordered and delivered quantities may not be the same. You have to choose if you want your invoice based on ordered or shipped quantities. If the product is a service, shipped quantities means hours spent on the associated tasks.", required=True, readonly=True, states={'draft': [('readonly', False)]}),
'payment_term': fields.many2one('account.payment.term', 'Payment Term'),
'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position'),
'company_id': fields.related('shop_id','company_id',type='many2one',relation='res.company',string='Company',store=True,readonly=True)
}
_defaults = {
- 'picking_policy': 'direct',
'date_order': fields.date.context_today,
- 'order_policy': 'manual',
+ 'order_policy': 'prepaid',
'state': 'draft',
'user_id': lambda obj, cr, uid, context: uid,
'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'sale.order'),
@@ -295,8 +238,7 @@ class sale_order(osv.osv):
if s['state'] in ['draft', 'cancel']:
unlink_ids.append(s['id'])
else:
- raise osv.except_osv(_('Invalid action !'), _('In order to delete a confirmed sale order, you must cancel it before ! To cancel a sale order, you must first cancel related picking or delivery orders.'))
-
+ raise osv.except_osv(_('Invalid action !'), _('In order to delete a confirmed sale order, you must cancel it before !'))
return osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
def onchange_shop_id(self, cr, uid, ids, shop_id):
@@ -309,20 +251,6 @@ class sale_order(osv.osv):
v['pricelist_id'] = shop.pricelist_id.id
return {'value': v}
- def action_cancel_draft(self, cr, uid, ids, context=None):
- if not len(ids):
- return False
- cr.execute('select id from sale_order_line where order_id IN %s and state=%s', (tuple(ids), 'cancel'))
- line_ids = map(lambda x: x[0], cr.fetchall())
- self.write(cr, uid, ids, {'state': 'draft', 'invoice_ids': [], 'shipped': 0})
- self.pool.get('sale.order.line').write(cr, uid, line_ids, {'invoiced': False, 'state': 'draft', 'invoice_lines': [(6, 0, [])]})
- wf_service = netsvc.LocalService("workflow")
- for inv_id in ids:
- # Deleting the existing instance of workflow for SO
- wf_service.trg_delete(uid, 'sale.order', inv_id, cr)
- wf_service.trg_create(uid, 'sale.order', inv_id, cr)
- self.action_cancel_draft_send_note(cr, uid, ids, context=context)
- return True
def onchange_pricelist_id(self, cr, uid, ids, pricelist_id, order_lines, context={}):
if (not pricelist_id) or (not order_lines):
@@ -333,15 +261,6 @@ class sale_order(osv.osv):
}
return {'warning': warning}
- def onchange_partner_order_id(self, cr, uid, ids, order_id, invoice_id=False, shipping_id=False, context={}):
- if not order_id:
- return {}
- val = {}
- if not invoice_id:
- val['partner_invoice_id'] = order_id
- if not shipping_id:
- val['partner_shipping_id'] = order_id
- return {'value': val}
def onchange_partner_id(self, cr, uid, ids, part):
if not part:
@@ -364,30 +283,7 @@ class sale_order(osv.osv):
val['pricelist_id'] = pricelist
return {'value': val}
- def shipping_policy_change(self, cr, uid, ids, policy, context=None):
- if not policy:
- return {}
- inv_qty = 'order'
- if policy == 'prepaid':
- inv_qty = 'order'
- elif policy == 'picking':
- inv_qty = 'procurement'
- return {'value': {'invoice_quantity': inv_qty}}
-
- def write(self, cr, uid, ids, vals, context=None):
- if vals.get('order_policy', False):
- if vals['order_policy'] == 'prepaid':
- vals.update({'invoice_quantity': 'order'})
- elif vals['order_policy'] == 'picking':
- vals.update({'invoice_quantity': 'procurement'})
- return super(sale_order, self).write(cr, uid, ids, vals, context=context)
-
def create(self, cr, uid, vals, context=None):
- if vals.get('order_policy', False):
- if vals['order_policy'] == 'prepaid':
- vals.update({'invoice_quantity': 'order'})
- if vals['order_policy'] == 'picking':
- vals.update({'invoice_quantity': 'procurement'})
order = super(sale_order, self).create(cr, uid, vals, context=context)
if order:
self.create_send_note(cr, uid, [order], context=context)
@@ -547,46 +443,10 @@ class sale_order(osv.osv):
result.update(view_id = res and res[1] or False)
return result
-
- def action_view_delivery(self, cr, uid, ids, context=None):
- '''
- This function returns an action that display existing delivery orders of given sale order ids. It can either be a in a list or in a form view, if there is only one delivery order to show.
- '''
- mod_obj = self.pool.get('ir.model.data')
- result = {
- 'name': _('Delivery Order'),
- 'view_type': 'form',
- 'res_model': 'stock.picking',
- 'context': "{'type':'out'}",
- 'type': 'ir.actions.act_window',
- 'nodestroy': True,
- 'target': 'current',
- }
- #compute the number of delivery orders to display
- pick_ids = []
- for so in self.browse(cr, uid, ids, context=context):
- pick_ids += [picking.id for picking in so.picking_ids]
- #choose the view_mode accordingly
- if len(pick_ids) > 1:
- res = mod_obj.get_object_reference(cr, uid, 'stock', 'view_picking_out_tree')
- result.update({
- 'view_mode': 'tree,form',
- 'res_id': pick_ids or False
- })
- else:
- res = mod_obj.get_object_reference(cr, uid, 'stock', 'view_picking_out_form')
- result.update({
- 'view_mode': 'form',
- 'res_id': pick_ids and pick_ids[0] or False,
- })
- result.update(view_id = res and res[1] or False)
- return result
-
def action_invoice_create(self, cr, uid, ids, grouped=False, states=['confirmed', 'done', 'exception'], date_inv = False, context=None):
res = False
invoices = {}
invoice_ids = []
- picking_obj = self.pool.get('stock.picking')
invoice = self.pool.get('account.invoice')
obj_sale_order_line = self.pool.get('sale.order.line')
partner_currency = {}
@@ -625,8 +485,6 @@ class sale_order(osv.osv):
for o, l in val:
invoice_ref += o.name + '|'
self.write(cr, uid, [o.id], {'state': 'progress'})
- if o.order_policy == 'picking':
- picking_obj.write(cr, uid, map(lambda x: x.id, o.picking_ids), {'invoice_state': 'invoiced'})
cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (o.id, res))
invoice.write(cr, uid, [res], {'origin': invoice_ref, 'name': invoice_ref})
else:
@@ -634,8 +492,6 @@ class sale_order(osv.osv):
res = self._make_invoice(cr, uid, order, il, context=context)
invoice_ids.append(res)
self.write(cr, uid, [order.id], {'state': 'progress'})
- if order.order_policy == 'picking':
- picking_obj.write(cr, uid, map(lambda x: x.id, order.picking_ids), {'invoice_state': 'invoiced'})
cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (order.id, res))
if res:
self.invoice_send_note(cr, uid, ids, res, context)
@@ -697,22 +553,7 @@ class sale_order(osv.osv):
if context is None:
context = {}
sale_order_line_obj = self.pool.get('sale.order.line')
- proc_obj = self.pool.get('procurement.order')
for sale in self.browse(cr, uid, ids, context=context):
- for pick in sale.picking_ids:
- if pick.state not in ('draft', 'cancel'):
- raise osv.except_osv(
- _('Could not cancel sales order !'),
- _('You must first cancel all picking attached to this sales order.'))
- if pick.state == 'cancel':
- for mov in pick.move_lines:
- proc_ids = proc_obj.search(cr, uid, [('move_id', '=', mov.id)])
- if proc_ids:
- for proc in proc_ids:
- wf_service.trg_validate(uid, 'procurement.order', proc, 'button_check', cr)
- for r in self.read(cr, uid, ids, ['picking_ids']):
- for pick in r['picking_ids']:
- wf_service.trg_validate(uid, 'stock.picking', pick, 'button_cancel', cr)
for inv in sale.invoice_ids:
if inv.state not in ('draft', 'cancel'):
raise osv.except_osv(
@@ -751,10 +592,7 @@ class sale_order(osv.osv):
for o in self.browse(cr, uid, ids):
if not o.order_line:
raise osv.except_osv(_('Error !'),_('You cannot confirm a sale order which has no line.'))
- if (o.order_policy == 'manual'):
- self.write(cr, uid, [o.id], {'state': 'manual', 'date_confirm': fields.date.context_today(self, cr, uid, context=context)})
- else:
- self.write(cr, uid, [o.id], {'state': 'progress', 'date_confirm': fields.date.context_today(self, cr, uid, context=context)})
+ self.write(cr, uid, [o.id], {'state': 'progress', 'date_confirm': fields.date.context_today(self, cr, uid, context=context)})
self.pool.get('sale.order.line').button_confirm(cr, uid, [x.id for x in o.order_line])
self.confirm_send_note(cr, uid, ids, context)
return True
@@ -783,241 +621,6 @@ class sale_order(osv.osv):
'nodestroy': True,
}
- def procurement_lines_get(self, cr, uid, ids, *args):
- res = []
- for order in self.browse(cr, uid, ids, context={}):
- for line in order.order_line:
- if line.procurement_id:
- res.append(line.procurement_id.id)
- return res
-
- # if mode == 'finished':
- # returns True if all lines are done, False otherwise
- # if mode == 'canceled':
- # returns True if there is at least one canceled line, False otherwise
- def test_state(self, cr, uid, ids, mode, *args):
- assert mode in ('finished', 'canceled'), _("invalid mode for test_state")
- finished = True
- canceled = False
- notcanceled = False
- write_done_ids = []
- write_cancel_ids = []
- for order in self.browse(cr, uid, ids, context={}):
- for line in order.order_line:
- if (not line.procurement_id) or (line.procurement_id.state=='done'):
- if line.state != 'done':
- write_done_ids.append(line.id)
- else:
- finished = False
- if line.procurement_id:
- if (line.procurement_id.state == 'cancel'):
- canceled = True
- if line.state != 'exception':
- write_cancel_ids.append(line.id)
- else:
- notcanceled = True
- if write_done_ids:
- self.pool.get('sale.order.line').write(cr, uid, write_done_ids, {'state': 'done'})
- if write_cancel_ids:
- self.pool.get('sale.order.line').write(cr, uid, write_cancel_ids, {'state': 'exception'})
-
- if mode == 'finished':
- return finished
- elif mode == 'canceled':
- return canceled
- if notcanceled:
- return False
- return canceled
-
- def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, context=None):
- return {
- 'name': line.name.split('\n')[0],
- 'origin': order.name,
- 'date_planned': date_planned,
- 'product_id': line.product_id.id,
- 'product_qty': line.product_uom_qty,
- 'product_uom': line.product_uom.id,
- 'product_uos_qty': (line.product_uos and line.product_uos_qty)\
- or line.product_uom_qty,
- 'product_uos': (line.product_uos and line.product_uos.id)\
- or line.product_uom.id,
- 'location_id': order.shop_id.warehouse_id.lot_stock_id.id,
- 'procure_method': line.type,
- 'move_id': move_id,
- 'company_id': order.company_id.id,
- 'note': '\n'.join(line.name.split('\n')[1:]),
- 'property_ids': [(6, 0, [x.id for x in line.property_ids])]
- }
-
- def _prepare_order_line_move(self, cr, uid, order, line, picking_id, date_planned, context=None):
- location_id = order.shop_id.warehouse_id.lot_stock_id.id
- output_id = order.shop_id.warehouse_id.lot_output_id.id
- return {
- 'name': line.name.split('\n')[0][:250],
- 'picking_id': picking_id,
- 'product_id': line.product_id.id,
- 'date': date_planned,
- 'date_expected': date_planned,
- 'product_qty': line.product_uom_qty,
- 'product_uom': line.product_uom.id,
- 'product_uos_qty': (line.product_uos and line.product_uos_qty) or line.product_uom_qty,
- 'product_uos': (line.product_uos and line.product_uos.id)\
- or line.product_uom.id,
- 'product_packaging': line.product_packaging.id,
- 'partner_id': line.address_allotment_id.id or order.partner_shipping_id.id,
- 'location_id': location_id,
- 'location_dest_id': output_id,
- 'sale_line_id': line.id,
- 'tracking_id': False,
- 'state': 'draft',
- #'state': 'waiting',
- 'note': '\n'.join(line.name.split('\n')[1:]),
- 'company_id': order.company_id.id,
- 'price_unit': line.product_id.standard_price or 0.0
- }
-
- def _prepare_order_picking(self, cr, uid, order, context=None):
- pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out')
- return {
- 'name': pick_name,
- 'origin': order.name,
- 'date': order.date_order,
- 'type': 'out',
- 'state': 'auto',
- 'move_type': order.picking_policy,
- 'sale_id': order.id,
- 'partner_id': order.partner_shipping_id.id,
- 'note': order.note,
- 'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none',
- 'company_id': order.company_id.id,
- }
-
- def ship_recreate(self, cr, uid, order, line, move_id, proc_id):
- # FIXME: deals with potentially cancelled shipments, seems broken (specially if shipment has production lot)
- """
- Define ship_recreate for process after shipping exception
- param order: sale order to which the order lines belong
- param line: sale order line records to procure
- param move_id: the ID of stock move
- param proc_id: the ID of procurement
- """
- move_obj = self.pool.get('stock.move')
- if order.state == 'shipping_except':
- for pick in order.picking_ids:
- for move in pick.move_lines:
- if move.state == 'cancel':
- mov_ids = move_obj.search(cr, uid, [('state', '=', 'cancel'),('sale_line_id', '=', line.id),('picking_id', '=', pick.id)])
- if mov_ids:
- for mov in move_obj.browse(cr, uid, mov_ids):
- # FIXME: the following seems broken: what if move_id doesn't exist? What if there are several mov_ids? Shouldn't that be a sum?
- move_obj.write(cr, uid, [move_id], {'product_qty': mov.product_qty, 'product_uos_qty': mov.product_uos_qty})
- self.pool.get('procurement.order').write(cr, uid, [proc_id], {'product_qty': mov.product_qty, 'product_uos_qty': mov.product_uos_qty})
- return True
-
- def _get_date_planned(self, cr, uid, order, line, start_date, context=None):
- date_planned = datetime.strptime(start_date, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(days=line.delay or 0.0)
- date_planned = (date_planned - timedelta(days=order.company_id.security_lead)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
- return date_planned
-
- def _create_pickings_and_procurements(self, cr, uid, order, order_lines, picking_id=False, context=None):
- """Create the required procurements to supply sale order lines, also connecting
- the procurements to appropriate stock moves in order to bring the goods to the
- sale order's requested location.
-
- If ``picking_id`` is provided, the stock moves will be added to it, otherwise
- a standard outgoing picking will be created to wrap the stock moves, as returned
- by :meth:`~._prepare_order_picking`.
-
- Modules that wish to customize the procurements or partition the stock moves over
- multiple stock pickings may override this method and call ``super()`` with
- different subsets of ``order_lines`` and/or preset ``picking_id`` values.
-
- :param browse_record order: sale order to which the order lines belong
- :param list(browse_record) order_lines: sale order line records to procure
- :param int picking_id: optional ID of a stock picking to which the created stock moves
- will be added. A new picking will be created if ommitted.
- :return: True
- """
- move_obj = self.pool.get('stock.move')
- picking_obj = self.pool.get('stock.picking')
- procurement_obj = self.pool.get('procurement.order')
- proc_ids = []
-
- for line in order_lines:
- if line.state == 'done':
- continue
-
- date_planned = self._get_date_planned(cr, uid, order, line, order.date_order, context=context)
-
- if line.product_id:
- if line.product_id.product_tmpl_id.type in ('product', 'consu'):
- if not picking_id:
- picking_id = picking_obj.create(cr, uid, self._prepare_order_picking(cr, uid, order, context=context))
- move_id = move_obj.create(cr, uid, self._prepare_order_line_move(cr, uid, order, line, picking_id, date_planned, context=context))
- else:
- # a service has no stock move
- move_id = False
-
- proc_id = procurement_obj.create(cr, uid, self._prepare_order_line_procurement(cr, uid, order, line, move_id, date_planned, context=context))
- proc_ids.append(proc_id)
- line.write({'procurement_id': proc_id})
- self.ship_recreate(cr, uid, order, line, move_id, proc_id)
-
- wf_service = netsvc.LocalService("workflow")
- if picking_id:
- wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr)
- self.delivery_send_note(cr, uid, [order.id], picking_id, context)
-
-
- for proc_id in proc_ids:
- wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr)
-
- val = {}
- if order.state == 'shipping_except':
- val['state'] = 'progress'
- val['shipped'] = False
-
- if (order.order_policy == 'manual'):
- for line in order.order_line:
- if (not line.invoiced) and (line.state not in ('cancel', 'draft')):
- val['state'] = 'manual'
- break
- order.write(val)
- return True
-
- def action_ship_create(self, cr, uid, ids, context=None):
- for order in self.browse(cr, uid, ids, context=context):
- self._create_pickings_and_procurements(cr, uid, order, order.order_line, None, context=context)
- return True
-
- def action_ship_end(self, cr, uid, ids, context=None):
- for order in self.browse(cr, uid, ids, context=context):
- val = {'shipped': True}
- if order.state == 'shipping_except':
- val['state'] = 'progress'
- if (order.order_policy == 'manual'):
- for line in order.order_line:
- if (not line.invoiced) and (line.state not in ('cancel', 'draft')):
- val['state'] = 'manual'
- break
- for line in order.order_line:
- towrite = []
- if line.state == 'exception':
- towrite.append(line.id)
- if towrite:
- self.pool.get('sale.order.line').write(cr, uid, towrite, {'state': 'done'}, context=context)
- res = self.write(cr, uid, [order.id], val)
- if res:
- self.delivery_end_send_note(cr, uid, [order.id], context=context)
- return True
-
- def has_stockable_products(self, cr, uid, ids, *args):
- for order in self.browse(cr, uid, ids):
- for order_line in order.order_line:
- if order_line.product_id and order_line.product_id.product_tmpl_id.type in ('product', 'consu'):
- return True
- return False
-
# ------------------------------------------------
# OpenChatter methods and notifications
# ------------------------------------------------
@@ -1025,7 +628,7 @@ class sale_order(osv.osv):
def get_needaction_user_ids(self, cr, uid, ids, context=None):
result = super(sale_order, self).get_needaction_user_ids(cr, uid, ids, context=context)
for obj in self.browse(cr, uid, ids, context=context):
- if (obj.state == 'manual' or obj.state == 'progress'):
+ if (obj.state == 'progress'):
result[obj.id].append(obj.user_id.id)
return result
@@ -1042,18 +645,7 @@ class sale_order(osv.osv):
for obj in self.browse(cr, uid, ids, context=context):
self.message_append_note(cr, uid, [obj.id], body=_("Sale Order for %scancelled.") % (obj.partner_id.name), context=context)
- def delivery_send_note(self, cr, uid, ids, picking_id, context=None):
- for order in self.browse(cr, uid, ids, context=context):
- for picking in (pck for pck in order.picking_ids if pck.id == picking_id):
- # convert datetime field to a datetime, using server format, then
- # convert it to the user TZ and re-render it with %Z to add the timezone
- picking_datetime = fields.DT.datetime.strptime(picking.min_date, DEFAULT_SERVER_DATETIME_FORMAT)
- picking_date_str = fields.datetime.context_timestamp(cr, uid, picking_datetime, context=context).strftime(DATETIME_FORMATS_MAP['%+'] + " (%Z)")
- self.message_append_note(cr, uid, [order.id], body=_("Delivery Order %sscheduled for %s.") % (picking.name, picking_date_str), context=context)
-
- def delivery_end_send_note(self, cr, uid, ids, context=None):
- self.message_append_note(cr, uid, ids, body=_("Order delivered."), context=context)
-
+
def invoice_paid_send_note(self, cr, uid, ids, context=None):
self.message_append_note(cr, uid, ids, body=_("Invoice paid."), context=context)
@@ -1062,9 +654,6 @@ class sale_order(osv.osv):
for invoice in (inv for inv in order.invoice_ids if inv.id == invoice_id):
self.message_append_note(cr, uid, [order.id], body=_("Draft Invoice of %s %s waiting for validation.") % (invoice.amount_total, invoice.currency_id.symbol), context=context)
- def action_cancel_draft_send_note(self, cr, uid, ids, context=None):
- return self.message_append_note(cr, uid, ids, body='Sale order has been set in draft.', context=context)
-
sale_order()
@@ -1086,14 +675,7 @@ class sale_order_line(osv.osv):
res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
return res
- def _number_packages(self, cr, uid, ids, field_name, arg, context=None):
- res = {}
- for line in self.browse(cr, uid, ids, context=context):
- try:
- res[line.id] = int((line.product_uom_qty+line.product_packaging.qty-0.0001) / line.product_packaging.qty)
- except:
- res[line.id] = 1
- return res
+
def _get_uom_id(self, cr, uid, *args):
try:
@@ -1109,26 +691,18 @@ class sale_order_line(osv.osv):
'order_id': fields.many2one('sale.order', 'Order Reference', required=True, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]}),
'name': fields.text('Product Description', size=256, required=True, select=True, readonly=True, states={'draft': [('readonly', False)]}),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of sales order lines."),
- 'delay': fields.float('Delivery Lead Time', required=True, help="Number of days between the order confirmation the shipping of the products to the customer", readonly=True, states={'draft': [('readonly', False)]}),
'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], change_default=True),
'invoice_lines': fields.many2many('account.invoice.line', 'sale_order_line_invoice_rel', 'order_line_id', 'invoice_id', 'Invoice Lines', readonly=True),
'invoiced': fields.boolean('Invoiced', readonly=True),
- 'procurement_id': fields.many2one('procurement.order', 'Procurement'),
'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Sale Price'), readonly=True, states={'draft': [('readonly', False)]}),
'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute= dp.get_precision('Sale Price')),
'tax_id': fields.many2many('account.tax', 'sale_order_tax', 'order_line_id', 'tax_id', 'Taxes', readonly=True, states={'draft': [('readonly', False)]}),
- 'type': fields.selection([('make_to_stock', 'from stock'), ('make_to_order', 'on order')], 'Procurement Method', required=True, readonly=True, states={'draft': [('readonly', False)]},
- help="If 'on order', it triggers a procurement when the sale order is confirmed to create a task, purchase order or manufacturing order linked to this sale order line."),
- 'property_ids': fields.many2many('mrp.property', 'sale_order_line_property_rel', 'order_id', 'property_id', 'Properties', readonly=True, states={'draft': [('readonly', False)]}),
'address_allotment_id': fields.many2one('res.partner', 'Allotment Partner'),
'product_uom_qty': fields.float('Quantity', digits_compute= dp.get_precision('Product UoS'), required=True, readonly=True, states={'draft': [('readonly', False)]}),
'product_uom': fields.many2one('product.uom', 'Unit of Measure ', required=True, readonly=True, states={'draft': [('readonly', False)]}),
'product_uos_qty': fields.float('Quantity (UoS)' ,digits_compute= dp.get_precision('Product UoS'), readonly=True, states={'draft': [('readonly', False)]}),
'product_uos': fields.many2one('product.uom', 'Product UoS'),
- 'product_packaging': fields.many2one('product.packaging', 'Packaging'),
- 'move_ids': fields.one2many('stock.move', 'sale_line_id', 'Inventory Moves', readonly=True),
'discount': fields.float('Discount', digits=(16, 2), readonly=True, states={'draft': [('readonly', False)]}),
- 'number_packages': fields.function(_number_packages, type='integer', string='Number Packages'),
'th_weight': fields.float('Weight', readonly=True, states={'draft': [('readonly', False)]}),
'state': fields.selection([('cancel', 'Cancelled'),('draft', 'Draft'),('confirmed', 'Confirmed'),('exception', 'Exception'),('done', 'Done')], 'Status', required=True, readonly=True,
help='* The \'Draft\' state is set when the related sales order in draft state. \
@@ -1144,14 +718,11 @@ class sale_order_line(osv.osv):
_defaults = {
'product_uom' : _get_uom_id,
'discount': 0.0,
- 'delay': 0.0,
'product_uom_qty': 1,
'product_uos_qty': 1,
'sequence': 10,
'invoiced': 0,
'state': 'draft',
- 'type': 'make_to_stock',
- 'product_packaging': False,
'price_unit': 0.0,
}
@@ -1168,22 +739,16 @@ class sale_order_line(osv.osv):
"""
def _get_line_qty(line):
- if (line.order_id.invoice_quantity=='order') or not line.procurement_id:
+ if (line.order_id.invoice_quantity=='order'):
if line.product_uos:
return line.product_uos_qty or 0.0
return line.product_uom_qty
- else:
- return self.pool.get('procurement.order').quantity_get(cr, uid,
- line.procurement_id.id, context=context)
def _get_line_uom(line):
- if (line.order_id.invoice_quantity=='order') or not line.procurement_id:
+ if (line.order_id.invoice_quantity=='order'):
if line.product_uos:
return line.product_uos.id
return line.product_uom.id
- else:
- return self.pool.get('procurement.order').uom_get(cr, uid,
- line.procurement_id.id, context=context)
if not line.invoiced:
if not account_id:
@@ -1293,52 +858,6 @@ class sale_order_line(osv.osv):
default.update({'state': 'draft', 'move_ids': [], 'invoiced': False, 'invoice_lines': []})
return super(sale_order_line, self).copy_data(cr, uid, id, default, context=context)
- def product_packaging_change(self, cr, uid, ids, pricelist, product, qty=0, uom=False,
- partner_id=False, packaging=False, flag=False, context=None):
- if not product:
- return {'value': {'product_packaging': False}}
- product_obj = self.pool.get('product.product')
- product_uom_obj = self.pool.get('product.uom')
- pack_obj = self.pool.get('product.packaging')
- warning = {}
- result = {}
- warning_msgs = ''
- if flag:
- res = self.product_id_change(cr, uid, ids, pricelist=pricelist,
- product=product, qty=qty, uom=uom, partner_id=partner_id,
- packaging=packaging, flag=False, context=context)
- warning_msgs = res.get('warning') and res['warning']['message']
-
- products = product_obj.browse(cr, uid, product, context=context)
- if not products.packaging:
- packaging = result['product_packaging'] = False
- elif not packaging and products.packaging and not flag:
- packaging = products.packaging[0].id
- result['product_packaging'] = packaging
-
- if packaging:
- default_uom = products.uom_id and products.uom_id.id
- pack = pack_obj.browse(cr, uid, packaging, context=context)
- q = product_uom_obj._compute_qty(cr, uid, uom, pack.qty, default_uom)
-# qty = qty - qty % q + q
- if qty and (q and not (qty % q) == 0):
- ean = pack.ean or _('(n/a)')
- qty_pack = pack.qty
- type_ul = pack.ul
- if not warning_msgs:
- warn_msg = _("You selected a quantity of %d Units.\n"
- "But it's not compatible with the selected packaging.\n"
- "Here is a proposition of quantities according to the packaging:\n"
- "EAN: %s Quantity: %s Type of ul: %s") % \
- (qty, ean, qty_pack, type_ul.name)
- warning_msgs += _("Picking Information ! : ") + warn_msg + "\n\n"
- warning = {
- 'title': _('Configuration Error !'),
- 'message': warning_msgs
- }
- result['product_uom_qty'] = qty
-
- return {'value': result, 'warning': warning}
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
diff --git a/addons/sale/sale_data.xml b/addons/sale/sale_data.xml
index c93651219af..e87669a4d1a 100644
--- a/addons/sale/sale_data.xml
+++ b/addons/sale/sale_data.xml
@@ -10,7 +10,6 @@
-
diff --git a/addons/sale/sale_demo.xml b/addons/sale/sale_demo.xml
index d9946c812c7..938dc545979 100644
--- a/addons/sale/sale_demo.xml
+++ b/addons/sale/sale_demo.xml
@@ -11,9 +11,6 @@
- picking
- procurement
- Invoice after delivery
@@ -24,7 +21,6 @@
123.20
- make_to_stock
@@ -35,7 +31,6 @@
450.5033
- make_to_stock
@@ -44,8 +39,6 @@
9005
- make_to_stock
- 1
@@ -55,7 +48,6 @@
8855
- make_to_stock
@@ -80,7 +72,6 @@
540
- make_to_order
@@ -90,7 +81,6 @@
8888
- make_to_order
@@ -111,8 +101,6 @@
3450
- make_to_order
- 2
@@ -121,8 +109,6 @@
7503
- make_to_order
- 7
@@ -142,8 +128,6 @@
2450
- make_to_order
- 8
@@ -152,10 +136,7 @@
9005
- make_to_order
- 1
-
@@ -174,8 +155,6 @@
4750
- make_to_order
- 15
@@ -185,9 +164,7 @@
7533
- make_to_stock
-
@@ -206,8 +183,6 @@
4250
- make_to_order
- 15
@@ -216,11 +191,7 @@
4500
- make_to_order
- 15
-
-
@@ -239,8 +210,6 @@
15250
- make_to_stock
- 15
@@ -249,12 +218,8 @@
5500
- make_to_stock
- 15
-
-
diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml
index ac665df7a6b..a9edd29b9e1 100644
--- a/addons/sale/sale_view.xml
+++ b/addons/sale/sale_view.xml
@@ -22,9 +22,7 @@
+
sale.shopsale.shop
@@ -44,7 +43,6 @@
-
@@ -61,8 +59,7 @@
If you have more than one shop reselling your company products, you can create and manage that from here. Whenever you will record a new quotation or sales order, it has to be linked to a shop. The shop also defines the warehouse from which the products will be delivered for each particular sales.
-
+
@@ -136,7 +133,6 @@
-
@@ -154,24 +150,17 @@
-
-
-
-
+ attrs="{'invisible': ['|','|',('state', '!=','progress'), ('invoiced', '=', True)]}"/>
-
-
+
diff --git a/addons/sale/sale_workflow.xml b/addons/sale/sale_workflow.xml
index c18e271d480..7db2b6dbcbe 100644
--- a/addons/sale/sale_workflow.xml
+++ b/addons/sale/sale_workflow.xml
@@ -30,10 +30,6 @@
wait_invoice
-
-
- wait_ship
-
@@ -83,6 +79,7 @@
functionaction_invoice_end()
+
invoice_cancel
@@ -90,31 +87,6 @@
stopallaction_cancel()
-
-
- ship
- function
- action_ship_create()
-
-
-
- ship_except
- function
- write({'state':'shipping_except'})
-
-
-
- ship_end
- function
- action_ship_end()
-
-
-
- ship_cancel
- True
- stopall
- action_cancel()
-
@@ -159,6 +131,7 @@
all_lines
+
@@ -170,10 +143,6 @@
-
-
-
-
@@ -181,17 +150,6 @@
cancel
-
-
-
- cancel
-
-
-
-
-
- (order_policy!='prepaid') or invoiced
-
@@ -199,17 +157,13 @@
(order_policy=='prepaid')
-
-
-
- manual_invoice
- subflow.paid
+
@@ -230,38 +184,6 @@
invoice_cancel
-
-
-
-
-
-
-
-
- procurement.order
- procurement_lines_get()
- test_state('finished')
-
-
-
-
- test_state('canceled')
-
-
-
-
- ship_recreate
-
-
-
-
- ship_corrected
-
-
-
-
- ship_cancel
-
-
+
diff --git a/addons/sale/security/ir.model.access.csv b/addons/sale/security/ir.model.access.csv
index 617678eccbe..4d00f8bb212 100644
--- a/addons/sale/security/ir.model.access.csv
+++ b/addons/sale/security/ir.model.access.csv
@@ -9,13 +9,6 @@ access_account_invoice_manager,account_invoice manager,account.model_account_inv
access_account_invoice_line_salesman,account_invoice.line salesman,account.model_account_invoice_line,base.group_sale_salesman,1,1,1,0
access_account_payment_term_salesman,account_payment_term salesman,account.model_account_payment_term,base.group_sale_salesman,1,0,0,0
access_account_analytic_account_salesman,account_analytic_account salesman,analytic.model_account_analytic_account,base.group_sale_salesman,1,1,1,0
-access_stock_picking_salesman,stock_picking salesman,stock.model_stock_picking,base.group_sale_salesman,1,1,1,0
-access_stock_move_salesman,stock_move salesman,stock.model_stock_move,base.group_sale_salesman,1,1,1,0
-access_stock_move_manager,stock_move manager,stock.model_stock_move,base.group_sale_manager,1,1,1,1
-access_procurement_salesman,procurement.order salesman,procurement.model_procurement_order,base.group_sale_salesman,1,1,1,0
-access_procurement_manager,procurement.order manager,procurement.model_procurement_order,base.group_sale_manager,1,1,1,1
-access_sale_order_stock_worker,sale.order stock worker,model_sale_order,stock.group_stock_user,1,1,0,0
-access_sale_order_line_stock_worker,sale.order.line stock worker,model_sale_order_line,stock.group_stock_user,1,1,0,0
access_sale_order_manager,sale.order.manager,model_sale_order,base.group_sale_manager,1,1,1,1
access_sale_order_accountant,sale.order.accountant,model_sale_order,account.group_account_user,1,1,0,0
access_sale_report_salesman,sale.report,model_sale_report,base.group_sale_salesman,1,1,1,0
@@ -24,23 +17,19 @@ access_ir_property_sales,ir.property.sales,base.model_ir_property,base.group_sal
access_sale_account_journal,account.journal sale order.user,account.model_account_journal,base.group_sale_salesman,1,0,0,0
access_res_partner_sale_user,res.partner.sale.user,base.model_res_partner,base.group_sale_salesman,1,0,0,0
access_res_partner_sale_manager,res.partner.sale.manager,base.model_res_partner,base.group_sale_manager,1,1,1,0
-access_report_stock_move_sales,report.stock.move.sale,stock.model_report_stock_move,base.group_sale_manager,1,1,1,1
-access_stock_picking_sales,stock.picking.sales,stock.model_stock_picking,base.group_sale_manager,1,1,1,1
+
access_product_template_sale_user,product.template sale use,product.model_product_template,base.group_sale_salesman,1,0,0,0
access_product_product_sale_user,product.product sale use,product.model_product_product,base.group_sale_salesman,1,0,0,0
access_sale_shop_manager,account.journal sale order.user,model_sale_shop,base.group_sale_manager,1,1,1,1
access_account_fiscalyear_user,account.fiscalyear.user,account.model_account_fiscalyear,base.group_sale_salesman,1,0,0,0
access_account_tax_user,account.tax.user,account.model_account_tax,base.group_sale_salesman,1,0,0,0
-access_product_packaging_user,product.packaging.user,product.model_product_packaging,base.group_sale_salesman,1,1,1,0
+
access_ir_attachment_sales,ir.attachment.sales,base.model_ir_attachment,base.group_sale_salesman,1,1,1,0
access_ir_attachment_manager,ir.attachment.manager,base.model_ir_attachment,base.group_sale_manager,1,1,1,1
-access_product_packaging_manager,product.packaging.manager,product.model_product_packaging,base.group_sale_manager,1,0,0,0
-access_stock_warehouse_user,stock.warehouse.user,stock.model_stock_warehouse,base.group_sale_salesman,1,0,0,0
+
access_res_partner_bank_type_user,res.partner.bank.type.user,base.model_res_partner_bank_type,base.group_sale_salesman,1,0,0,0
-access_stock_location_user,stock.location.user,stock.model_stock_location,base.group_sale_salesman,1,0,0,0
access_res_partner_bank_type_field_user,res.partner.bank.type.field.user,base.model_res_partner_bank_type_field,base.group_sale_salesman,1,0,0,0
access_product_uom_user,product.uom.user,product.model_product_uom,base.group_sale_salesman,1,0,0,0
-access_product_supplierinfo_user,product.supplierinfo.user,product.model_product_supplierinfo,base.group_sale_salesman,1,0,0,0
access_product_pricelist_sale_user,product.pricelist.sale.user,product.model_product_pricelist,base.group_sale_salesman,1,0,0,0
access_account_account_salesman,account_account salesman,account.model_account_account,base.group_sale_salesman,1,0,0,0
access_sale_shop_sale_user,sale.shop.sale.user,model_sale_shop,base.group_sale_salesman,1,0,0,0
@@ -49,7 +38,7 @@ access_product_uom_categ_sale_manager,product.uom.categ salemanager,product.mode
access_product_uom_sale_manager,product.uom salemanager,product.model_product_uom,base.group_sale_manager,1,1,1,1
access_product_ul_sale_manager,product.ul salemanager,product.model_product_ul,base.group_sale_manager,1,1,1,1
access_product_category_sale_manager,product.category salemanager,product.model_product_category,base.group_sale_manager,1,1,1,1
-access_product_packaging_sale_manager,product.packaging salemanager,product.model_product_packaging,base.group_sale_manager,1,1,1,1
+access_product_supplierinfo_user,product.supplierinfo.user,product.model_product_supplierinfo,base.group_sale_salesman,1,0,0,0
access_product_supplierinfo_sale_manager,product.supplierinfo salemanager,product.model_product_supplierinfo,base.group_sale_manager,1,1,1,1
access_pricelist_partnerinfo_sale_manager,pricelist.partnerinfo salemanager,product.model_pricelist_partnerinfo,base.group_sale_manager,1,1,1,1
access_product_price_type_sale_manager,product.price.type salemanager,product.model_product_price_type,base.group_sale_manager,1,1,1,1
@@ -58,5 +47,3 @@ access_product_pricelist_sale_manager,product.pricelist salemanager,product.mode
access_product_group_res_partner_sale_manager,res_partner group_sale_manager,base.model_res_partner,base.group_sale_manager,1,1,1,0
access_product_pricelist_version_sale_manager,product.pricelist.version sale_manager,product.model_product_pricelist_version,base.group_sale_manager,1,1,1,1
access_account_invoice_report_salesman,account.invoice.report salesman,account.model_account_invoice_report,base.group_sale_salesman,1,0,0,0
-access_stock_warehouse_orderpoint_sale_salesman,stock.warehouse.orderpoint,procurement.model_stock_warehouse_orderpoint,base.group_sale_salesman,1,0,0,0
-access_account_move_line_salesman,account.move.line invoice,account.model_account_move_line,base.group_sale_salesman,1,0,0,0
diff --git a/addons/sale/security/sale_security.xml b/addons/sale/security/sale_security.xml
index 47a577e77c3..8b64b360435 100644
--- a/addons/sale/security/sale_security.xml
+++ b/addons/sale/security/sale_security.xml
@@ -25,21 +25,12 @@
-
- Enable Invoicing Delivery orders
-
- Addresses in Sale Orders
-
- Properties on lines
-
-
-
Discount on lines
diff --git a/addons/sale/test/cancel_order.yml b/addons/sale/test/cancel_order.yml
index cfdd0c7f079..afc629306fe 100644
--- a/addons/sale/test/cancel_order.yml
+++ b/addons/sale/test/cancel_order.yml
@@ -1,67 +1,20 @@
-
In order to test the cancel sale order.
--
- Now I cancel Quotation.
--
- !python {model: sale.order}: |
- self.action_cancel(cr, uid, [ref("order7")])
--
- I check state of Quotation after cancelled.
--
- !assert {model: sale.order, id: order7, string: sale order should be in cancel state}:
- - state == 'cancel'
--
- I set cancelled quotation to draft.
--
- !python {model: sale.order}: |
- self.action_cancel_draft(cr, uid, [ref("order7")])
--
- I confirm order.
+
+ First I confirm order.
-
!workflow {model: sale.order, action: order_confirm, ref: order7}
-
- I send delivery in two shipments, so I am doing a partial delivery order.
--
- !python {model: stock.picking}: |
- delivery_orders = self.search(cr, uid, [('sale_id','=',ref("order7"))])
- first_picking = self.browse(cr, uid, delivery_orders[0], context=context)
- if first_picking.force_assign(cr, uid, first_picking):
- first_move = first_picking.move_lines[0]
- values = {'move%s'%(first_move.id): {'product_qty': 5, 'product_uom':ref('product.product_uom_unit')}}
- first_picking.do_partial(values, context=context)
--
- Now I cancel latest shipment.
--
- !python {model: stock.picking}: |
- import netsvc
- delivery_orders = self.search(cr, uid, [('sale_id','=',ref("order7"))])
- last_delivery_order_id = delivery_orders[0]
- wf_service = netsvc.LocalService("workflow")
- wf_service.trg_validate(uid, 'stock.picking', last_delivery_order_id, 'button_cancel', cr)
--
- I run the scheduler.
--
- !python {model: procurement.order}: |
-
- self.run_scheduler(cr, uid)
--
- I check order status in "Ship Exception".
--
- !assert {model: sale.order, id: order7, string: Sale order should be in shipping exception}:
- - state == "shipping_except"
--
- Now I regenerate shipment.
--
- !workflow {model: sale.order, action: ship_recreate, ref: order7}
--
- I check state of order in 'To Invoice'.
+ I check state of order in 'Sale Order'.
-
!assert {model: sale.order, id: order7, string: Sale order should be In Progress state}:
- - state == 'manual'
+ - state == 'progress'
+-
+ I check that Invoice should be created.
-
- I make invoice for order.
--
- !workflow {model: sale.order, action: manual_invoice, ref: order7}
+ !python {model: sale.order}: |
+ sale_order = self.browse(cr, uid, ref("order7"))
+ assert len(sale_order.invoice_ids) == True, "Invoice should be created."
-
To cancel the sale order from Invoice Exception, I have to cancel the invoice of sale order.
-
@@ -80,9 +33,3 @@
Then I click on the Ignore Exception button.
-
!workflow {model: sale.order, action: invoice_corrected, ref: order7}
-
--
- I check state of order in 'In Progress'.
--
- !assert {model: sale.order, id: order7, string: Sale order should be In progress state}:
- - state == 'progress'
diff --git a/addons/sale/test/delete_order.yml b/addons/sale/test/delete_order.yml
index 2bbfed9771d..a42d5c34867 100644
--- a/addons/sale/test/delete_order.yml
+++ b/addons/sale/test/delete_order.yml
@@ -10,5 +10,5 @@
I make duplicate order and delete.
-
!python {model: sale.order}: |
- id = self.copy(cr, uid, ref('order'))
+ id = self.copy(cr, uid, ref('order4'))
self.unlink(cr, uid, [id])
diff --git a/addons/sale/test/edi_sale_order.yml b/addons/sale/test/edi_sale_order.yml
index af9a9b3aad6..d9fdb7ad8da 100644
--- a/addons/sale/test/edi_sale_order.yml
+++ b/addons/sale/test/edi_sale_order.yml
@@ -108,12 +108,12 @@
assert len(order_new.order_line) == 2, "Sale order lines mismatch"
for sale_line in order_new.order_line:
if sale_line.name == 'Basic PC':
- assert sale_line.delay == 18 , "incorrect delay: got %s, expected 18"%(sale_line.delay,)
+ # assert sale_line.delay == 18 , "incorrect delay: got %s, expected 18"%(sale_line.delay,)
assert sale_line.product_uom.name == "Unit" , "uom is not same"
assert sale_line.price_unit == 150 , "unit price is not same, got %s, expected 150"%(sale_line.price_unit,)
assert sale_line.product_uom_qty == 1 , "product qty is not same"
elif sale_line.name == 'Medium PC':
- assert sale_line.delay == 3 , "incorrect delay: got %s, expected 3"%(sale_line.delay,)
+ # assert sale_line.delay == 3 , "incorrect delay: got %s, expected 3"%(sale_line.delay,)
assert sale_line.product_uom.name == "Unit" , "uom is not same"
assert sale_line.price_unit == 100 , "unit price is not same, got %s, expected 100"%(sale_line.price_unit,)
assert sale_line.product_uom_qty == 2 , "product qty is not same"
diff --git a/addons/sale/test/prepaid_order_policy.yml b/addons/sale/test/prepaid_order_policy.yml
index 4f45baa8823..07754c03dfe 100644
--- a/addons/sale/test/prepaid_order_policy.yml
+++ b/addons/sale/test/prepaid_order_policy.yml
@@ -7,5 +7,4 @@
-
!python {model: sale.order}: |
sale_order = self.browse(cr, uid, ref("order3"))
- assert len(sale_order.picking_ids) == False, "Delivery order should not created before invoice."
assert sale_order.invoice_ids, "Invoice should be created."
diff --git a/addons/sale/wizard/__init__.py b/addons/sale/wizard/__init__.py
index 6cf076164d8..f243b959526 100644
--- a/addons/sale/wizard/__init__.py
+++ b/addons/sale/wizard/__init__.py
@@ -18,9 +18,6 @@
# along with this program. If not, see .
#
##############################################################################
-
-import sale_make_invoice
import sale_line_invoice
-import sale_make_invoice_advance
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
diff --git a/addons/sale_crm/__openerp__.py b/addons/sale_crm/__openerp__.py
index b56d866f98b..f4137047fff 100644
--- a/addons/sale_crm/__openerp__.py
+++ b/addons/sale_crm/__openerp__.py
@@ -37,7 +37,7 @@ modules.
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'images': ['images/crm_statistics_dashboard.jpeg', 'images/opportunity_to_quote.jpeg'],
- 'depends': ['sale', 'crm'],
+ 'depends': ['sale_stock', 'crm'],
'init_xml': [],
'update_xml': ['wizard/crm_make_sale_view.xml',
'sale_crm_view.xml',
diff --git a/addons/sale_journal/__openerp__.py b/addons/sale_journal/__openerp__.py
index 11408161bf4..6373cce1810 100644
--- a/addons/sale_journal/__openerp__.py
+++ b/addons/sale_journal/__openerp__.py
@@ -49,7 +49,7 @@ Some statistics by journals are provided.
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'images': ['images/invoice_type.jpeg'],
- 'depends': ['sale'],
+ 'depends': ['sale_stock'],
'init_xml': ['sale_journal_data.xml'],
'update_xml': [
'security/ir.model.access.csv',
diff --git a/addons/sale_margin/__openerp__.py b/addons/sale_margin/__openerp__.py
index 936f5a6b350..4e622e71b33 100644
--- a/addons/sale_margin/__openerp__.py
+++ b/addons/sale_margin/__openerp__.py
@@ -31,7 +31,7 @@ Price and Cost Price.
""",
"author":"OpenERP SA",
"images":["images/sale_margin.jpeg"],
- "depends":["sale"],
+ "depends":["sale_stock"],
"demo_xml":[],
'test': ['test/sale_margin.yml'],
"update_xml":["security/ir.model.access.csv","sale_margin_view.xml"],
diff --git a/addons/sale_mrp/__openerp__.py b/addons/sale_mrp/__openerp__.py
index d5b3d6b7849..b1aed2c67b5 100644
--- a/addons/sale_mrp/__openerp__.py
+++ b/addons/sale_mrp/__openerp__.py
@@ -34,7 +34,7 @@ from sales order. It adds sales name and sales Reference on production order.
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'images': ['images/SO_to_MO.jpeg'],
- 'depends': ['mrp', 'sale'],
+ 'depends': ['mrp', 'sale_stock'],
'init_xml': [],
'update_xml': [
'security/ir.model.access.csv',
diff --git a/addons/sale_stock/__init__.py b/addons/sale_stock/__init__.py
new file mode 100644
index 00000000000..1b63b8b2b8b
--- /dev/null
+++ b/addons/sale_stock/__init__.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+import sale_stock
+import stock
+import wizard
+import report
+import company
+import res_config
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
diff --git a/addons/sale_stock/__openerp__.py b/addons/sale_stock/__openerp__.py
new file mode 100644
index 00000000000..268e641cf41
--- /dev/null
+++ b/addons/sale_stock/__openerp__.py
@@ -0,0 +1,87 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+{
+ 'name': 'Sale To Stock',
+ 'version': '1.0',
+ 'category': 'Hidden',
+ 'description': """
+This Module manage quotations and sales orders.
+===========================================================================
+
+Workflow with validation steps:
+-------------------------------
+ * Quotation -> Sales order -> Invoice
+
+Create Invoice:
+---------------
+ * Invoice on Demand
+ * Invoice on Delivery Order
+ * Invoice Before Delivery
+
+Partners preferences:
+---------------------
+ * Incoterm
+ * Shipping
+ * Invoicing
+
+Products stocks and prices:
+--------------------------
+
+Delivery method:
+-----------------
+ * The Poste
+ * Free Delivery Charges
+ * Normal Delivery Charges
+ * Based on the Delivery Order(if not Add to sale order)
+
+Dashboard for Sales Manager that includes:
+------------------------------------------
+ * My Quotations
+ * Monthly Turnover (Graph)
+ """,
+ 'author': 'OpenERP SA',
+ 'website': 'http://www.openerp.com',
+ 'images': [],
+ 'depends': ['sale', 'procurement'],
+ 'init_xml': [],
+ 'update_xml': ['wizard/sale_make_invoice_advance.xml',
+ 'wizard/sale_make_invoice.xml',
+ 'security/sale_stock_security.xml',
+ 'security/ir.model.access.csv',
+ 'company_view.xml',
+ 'sale_stock_view.xml',
+ 'sale_stock_workflow.xml',
+ 'res_config_view.xml',
+ 'report/sale_report_view.xml',
+ 'process/sale_stock_process.xml',
+ ],
+ 'data': ['sale_stock_data.xml'],
+ 'demo_xml': ['sale_stock_demo.xml'],
+ 'test': ['test/cancel_order_sale_stock.yml',
+ 'test/picking_order_policy.yml',
+ 'test/manual_order_policy.yml'
+ ],
+ 'installable': True,
+ 'auto_install': True,
+
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
diff --git a/addons/sale/company.py b/addons/sale_stock/company.py
similarity index 100%
rename from addons/sale/company.py
rename to addons/sale_stock/company.py
diff --git a/addons/sale/company_view.xml b/addons/sale_stock/company_view.xml
similarity index 100%
rename from addons/sale/company_view.xml
rename to addons/sale_stock/company_view.xml
diff --git a/addons/sale_stock/process/sale_stock_process.xml b/addons/sale_stock/process/sale_stock_process.xml
new file mode 100644
index 00000000000..cee587dca9b
--- /dev/null
+++ b/addons/sale_stock/process/sale_stock_process.xml
@@ -0,0 +1,142 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/sale_stock/report/__init__.py b/addons/sale_stock/report/__init__.py
new file mode 100644
index 00000000000..418927acc78
--- /dev/null
+++ b/addons/sale_stock/report/__init__.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+import sale_report
\ No newline at end of file
diff --git a/addons/sale_stock/report/sale_report.py b/addons/sale_stock/report/sale_report.py
new file mode 100644
index 00000000000..5e9b74386b3
--- /dev/null
+++ b/addons/sale_stock/report/sale_report.py
@@ -0,0 +1,93 @@
+ # -*- coding: utf-8 -*-
+ ##############################################################################
+ #
+ # OpenERP, Open Source Management Solution
+ # Copyright (C) 2004-2010 Tiny SPRL ().
+ #
+ # This program is free software: you can redistribute it and/or modify
+ # it under the terms of the GNU Affero General Public License as
+ # published by the Free Software Foundation, either version 3 of the
+ # License, or (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU Affero General Public License for more details.
+ #
+ # You should have received a copy of the GNU Affero General Public License
+ # along with this program. If not, see .
+ #
+ ##############################################################################
+
+from osv import fields, osv
+import tools
+class sale_report(osv.osv):
+ _inherit = "sale.report"
+ _columns = {
+ 'shipped': fields.boolean('Shipped', readonly=True),
+ 'shipped_qty_1': fields.integer('Shipped', readonly=True),
+ 'state': fields.selection([
+ ('draft', 'Quotation'),
+ ('waiting_date', 'Waiting Schedule'),
+ ('manual', 'Manual In Progress'),
+ ('progress', 'In Progress'),
+ ('shipping_except', 'Shipping Exception'),
+ ('invoice_except', 'Invoice Exception'),
+ ('done', 'Done'),
+ ('cancel', 'Cancelled')
+ ], 'Order State', readonly=True),
+ }
+
+ def init(self, cr):
+ tools.drop_view_if_exists(cr, 'sale_report')
+ cr.execute("""
+ create or replace view sale_report as (
+ select
+ min(l.id) as id,
+ l.product_id as product_id,
+ t.uom_id as product_uom,
+ sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty,
+ sum(l.product_uom_qty * l.price_unit * (100.0-l.discount) / 100.0) as price_total,
+ 1 as nbr,
+ s.date_order as date,
+ s.date_confirm as date_confirm,
+ to_char(s.date_order, 'YYYY') as year,
+ to_char(s.date_order, 'MM') as month,
+ to_char(s.date_order, 'YYYY-MM-DD') as day,
+ s.partner_id as partner_id,
+ s.user_id as user_id,
+ s.shop_id as shop_id,
+ s.company_id as company_id,
+ extract(epoch from avg(date_trunc('day',s.date_confirm)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay,
+ s.state,
+ t.categ_id as categ_id,
+ s.shipped,
+ s.shipped::integer as shipped_qty_1,
+ s.pricelist_id as pricelist_id,
+ s.project_id as analytic_account_id
+ from
+ sale_order s
+ left join sale_order_line l on (s.id=l.order_id)
+ left join product_product p on (l.product_id=p.id)
+ left join product_template t on (p.product_tmpl_id=t.id)
+ left join product_uom u on (u.id=l.product_uom)
+ left join product_uom u2 on (u2.id=t.uom_id)
+ group by
+ l.product_id,
+ l.product_uom_qty,
+ l.order_id,
+ t.uom_id,
+ t.categ_id,
+ s.date_order,
+ s.date_confirm,
+ s.partner_id,
+ s.user_id,
+ s.shop_id,
+ s.company_id,
+ s.state,
+ s.shipped,
+ s.pricelist_id,
+ s.project_id
+ )
+ """)
+sale_report()
diff --git a/addons/sale_stock/report/sale_report_view.xml b/addons/sale_stock/report/sale_report_view.xml
new file mode 100644
index 00000000000..99aefa7e66f
--- /dev/null
+++ b/addons/sale_stock/report/sale_report_view.xml
@@ -0,0 +1,16 @@
+
+
+
+
+ sale.report.tree.sale.stock
+ sale.report
+
+ tree
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/addons/sale_stock/res_config.py b/addons/sale_stock/res_config.py
new file mode 100644
index 00000000000..30ee56753fe
--- /dev/null
+++ b/addons/sale_stock/res_config.py
@@ -0,0 +1,86 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Business Applications
+# Copyright (C) 2004-2012 OpenERP S.A. ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+from osv import fields, osv
+import pooler
+from tools.translate import _
+
+class sale_configuration(osv.osv_memory):
+ _inherit = 'sale.config.settings'
+ _columns = {
+ 'group_invoice_deli_orders': fields.boolean('Based on Delivery Orders',
+ implied_group='group_invoice_deli_orders',
+ help="To allow your salesman to make invoices for Delivery Orders using the menu 'Deliveries to Invoice'."),
+ 'task_work': fields.boolean('Based on Task Activities',
+ help="""Lets you transfer the entries under tasks defined for Project Management to
+ the Timesheet line entries for particular date and particular user with the effect of creating, editing and deleting either ways
+ and to automatically creates project tasks from procurement lines.
+ This installs the modules project_timesheet and project_mrp."""),
+ 'default_order_policy': fields.selection(
+ [('manual', 'Invoice Based on Sales Orders'), ('picking', 'Invoice Based on Deliveries')],
+ 'Default Method', default_model='sale.order',
+ help="You can generate invoices based on sales orders or based on shippings."),
+ 'module_delivery': fields.boolean('Allow Charging Shipping Costs',
+ help ="""Allows you to add delivery methods in sale orders and delivery orders.
+ You can define your own carrier and delivery grids for prices.
+ This installs the module delivery."""),
+ 'default_picking_policy' : fields.boolean("Configurable Shipping Policy",
+ help = "You will be able to configure, per sale order, if you deliver all products at once or if you deliver each product when it is available. This may have an impact on the shipping price."),
+ 'group_mrp_properties': fields.boolean('Properties on Lines',
+ implied_group='sale.group_mrp_properties',
+ help="Allows you to tag sale order lines with properties."),
+ 'group_multiple_shops': fields.boolean("Manage Multiple Shops",
+ implied_group='stock.group_locations',
+ help="This allows to configure and use multiple shops."),
+ 'module_project_timesheet': fields.boolean("Project Timesheet"),
+ 'module_project_mrp': fields.boolean("Project MRP"),
+
+ }
+
+ def default_get(self, cr, uid, fields, context=None):
+ res = super(sale_configuration, self).default_get(cr, uid, fields, context)
+ # task_work, time_unit depend on other fields
+ res['task_work'] = res.get('module_project_mrp') and res.get('module_project_timesheet')
+ return res
+
+ def get_default_sale_config(self, cr, uid, ids, context=None):
+ ir_values = self.pool.get('ir.values')
+ default_picking_policy = ir_values.get_default(cr, uid, 'sale.order', 'picking_policy')
+ return {
+ 'default_picking_policy': default_picking_policy == 'one',
+ }
+
+ def set_sale_defaults(self, cr, uid, ids, context=None):
+ ir_values = self.pool.get('ir.values')
+ ir_model_data = self.pool.get('ir.model.data')
+ wizard = self.browse(cr, uid, ids)[0]
+
+ default_picking_policy = 'one' if wizard.default_picking_policy else 'direct'
+ ir_values.set_default(cr, uid, 'sale.order', 'picking_policy', default_picking_policy)
+ res = super(sale_configuration, self).set_sale_defaults(cr, uid, ids, context)
+ return res
+
+ def onchange_invoice_methods(self, cr, uid, ids, group_invoice_so_lines, group_invoice_deli_orders, context=None):
+ if not group_invoice_deli_orders:
+ return {'value': {'default_order_policy': 'manual'}}
+ if not group_invoice_so_lines:
+ return {'value': {'default_order_policy': 'picking'}}
+ return {}
diff --git a/addons/sale_stock/res_config_view.xml b/addons/sale_stock/res_config_view.xml
new file mode 100644
index 00000000000..e68aa3b5662
--- /dev/null
+++ b/addons/sale_stock/res_config_view.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+ sale settings
+ sale.config.settings
+ form
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py
new file mode 100644
index 00000000000..3c43587a199
--- /dev/null
+++ b/addons/sale_stock/sale_stock.py
@@ -0,0 +1,639 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+from datetime import datetime, timedelta
+from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare
+from dateutil.relativedelta import relativedelta
+from osv import fields, osv
+import netsvc
+from tools.translate import _
+
+class sale_shop(osv.osv):
+ _inherit = "sale.shop"
+ _columns = {
+ 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse'),
+ }
+
+class sale_order(osv.osv):
+ _inherit = "sale.order"
+
+ def copy(self, cr, uid, id, default=None, context=None):
+ if not default:
+ default = {}
+ default.update({
+ 'shipped': False,
+ 'picking_ids': [],
+ })
+ return super(sale_order, self).copy(cr, uid, id, default, context=context)
+
+ def shipping_policy_change(self, cr, uid, ids, policy, context=None):
+ if not policy:
+ return {}
+ inv_qty = 'order'
+ if policy == 'prepaid':
+ inv_qty = 'order'
+ elif policy == 'picking':
+ inv_qty = 'procurement'
+ return {'value': {'invoice_quantity': inv_qty}}
+
+ def write(self, cr, uid, ids, vals, context=None):
+ if vals.get('order_policy', False):
+ if vals['order_policy'] == 'prepaid':
+ vals.update({'invoice_quantity': 'order'})
+ elif vals['order_policy'] == 'picking':
+ vals.update({'invoice_quantity': 'procurement'})
+ return super(sale_order, self).write(cr, uid, ids, vals, context=context)
+
+ def create(self, cr, uid, vals, context=None):
+ if vals.get('order_policy', False):
+ if vals['order_policy'] == 'prepaid':
+ vals.update({'invoice_quantity': 'order'})
+ if vals['order_policy'] == 'picking':
+ vals.update({'invoice_quantity': 'procurement'})
+ order = super(sale_order, self).create(cr, uid, vals, context=context)
+ return order
+
+ # This is False
+ def _picked_rate(self, cr, uid, ids, name, arg, context=None):
+ if not ids:
+ return {}
+ res = {}
+ tmp = {}
+ for id in ids:
+ tmp[id] = {'picked': 0.0, 'total': 0.0}
+ cr.execute('''SELECT
+ p.sale_id as sale_order_id, sum(m.product_qty) as nbr, mp.state as procurement_state, m.state as move_state, p.type as picking_type
+ FROM
+ stock_move m
+ LEFT JOIN
+ stock_picking p on (p.id=m.picking_id)
+ LEFT JOIN
+ procurement_order mp on (mp.move_id=m.id)
+ WHERE
+ p.sale_id IN %s GROUP BY m.state, mp.state, p.sale_id, p.type''', (tuple(ids),))
+
+ for item in cr.dictfetchall():
+ if item['move_state'] == 'cancel':
+ continue
+
+ if item['picking_type'] == 'in':#this is a returned picking
+ tmp[item['sale_order_id']]['total'] -= item['nbr'] or 0.0 # Deducting the return picking qty
+ if item['procurement_state'] == 'done' or item['move_state'] == 'done':
+ tmp[item['sale_order_id']]['picked'] -= item['nbr'] or 0.0
+ else:
+ tmp[item['sale_order_id']]['total'] += item['nbr'] or 0.0
+ if item['procurement_state'] == 'done' or item['move_state'] == 'done':
+ tmp[item['sale_order_id']]['picked'] += item['nbr'] or 0.0
+
+ for order in self.browse(cr, uid, ids, context=context):
+ if order.shipped:
+ res[order.id] = 100.0
+ else:
+ res[order.id] = tmp[order.id]['total'] and (100.0 * tmp[order.id]['picked'] / tmp[order.id]['total']) or 0.0
+ return res
+
+ _columns = {
+ 'state': fields.selection([
+ ('draft', 'Draft Quotation'),
+ ('sent', 'Quotation Sent'),
+ ('cancel', 'Cancelled'),
+ ('waiting_date', 'Waiting Schedule'),
+ ('progress', 'Sale Order'),
+ ('manual', 'Sale to Invoice'),
+ ('shipping_except', 'Shipping Exception'),
+ ('invoice_except', 'Invoice Exception'),
+ ('done', 'Done'),
+ ], 'Status', readonly=True,help="Gives the state of the quotation or sales order.\
+ \nThe exception state is automatically set when a cancel operation occurs \
+ in the invoice validation (Invoice Exception) or in the picking list process (Shipping Exception).\nThe 'Waiting Schedule' state is set when the invoice is confirmed\
+ but waiting for the scheduler to run on the order date.", select=True),
+ 'incoterm': fields.many2one('stock.incoterms', 'Incoterm', help="Incoterm which stands for 'International Commercial terms' implies its a series of sales terms which are used in the commercial transaction."),
+ 'picking_policy': fields.selection([('direct', 'Deliver each product when available'), ('one', 'Deliver all products at once')],
+ 'Shipping Policy', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
+ help="""If you don't have enough stock available to deliver all at once, do you accept partial shipments or not?"""),
+ 'order_policy': fields.selection([
+ ('manual', 'On Demand'),
+ ('picking', 'On Delivery Order'),
+ ('prepaid', 'Before Delivery'),
+ ], 'Create Invoice', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
+ help="""This field controls how invoice and delivery operations are synchronized.
+ - With 'On Demand', the invoice is created manually when needed.
+ - With 'On Delivery Order', a draft invoice is generated after all pickings have been processed.
+ - With 'Before Delivery', a draft invoice is created, and it must be paid before delivery."""),
+ 'picking_ids': fields.one2many('stock.picking.out', 'sale_id', 'Related Picking', readonly=True, help="This is a list of delivery orders that has been generated for this sales order."),
+ 'shipped': fields.boolean('Delivered', readonly=True, help="It indicates that the sales order has been delivered. This field is updated only after the scheduler(s) have been launched."),
+ 'picked_rate': fields.function(_picked_rate, string='Picked', type='float'),
+ 'invoice_quantity': fields.selection([('order', 'Ordered Quantities'), ('procurement', 'Shipped Quantities')], 'Invoice on',
+ help="The sale order will automatically create the invoice proposition (draft invoice).\
+ You have to choose if you want your invoice based on ordered ", required=True, readonly=True, states={'draft': [('readonly', False)]}),
+ }
+ _defaults = {
+ 'picking_policy': 'direct',
+ 'order_policy': 'manual',
+ 'invoice_quantity': 'order',
+ }
+
+ # Form filling
+ def unlink(self, cr, uid, ids, context=None):
+ sale_orders = self.read(cr, uid, ids, ['state'], context=context)
+ unlink_ids = []
+ for s in sale_orders:
+ if s['state'] in ['draft', 'cancel']:
+ unlink_ids.append(s['id'])
+ else:
+ raise osv.except_osv(_('Invalid action !'), _('In order to delete a confirmed sale order, you must cancel it before ! To cancel a sale order, you must first cancel related picking or delivery orders.'))
+
+ return osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
+
+
+
+ def action_view_delivery(self, cr, uid, ids, context=None):
+ '''
+ This function returns an action that display existing delivery orders of given sale order ids. It can either be a in a list or in a form view, if there is only one delivery order to show.
+ '''
+ mod_obj = self.pool.get('ir.model.data')
+ result = {
+ 'name': _('Delivery Order'),
+ 'view_type': 'form',
+ 'res_model': 'stock.picking',
+ 'context': "{'type':'out'}",
+ 'type': 'ir.actions.act_window',
+ 'nodestroy': True,
+ 'target': 'current',
+ }
+ #compute the number of delivery orders to display
+ pick_ids = []
+ for so in self.browse(cr, uid, ids, context=context):
+ pick_ids += [picking.id for picking in so.picking_ids]
+ #choose the view_mode accordingly
+ if len(pick_ids) > 1:
+ res = mod_obj.get_object_reference(cr, uid, 'stock', 'view_picking_out_tree')
+ result.update({
+ 'view_mode': 'tree,form',
+ 'res_id': pick_ids or False
+ })
+ else:
+ res = mod_obj.get_object_reference(cr, uid, 'stock', 'view_picking_out_form')
+ result.update({
+ 'view_mode': 'form',
+ 'res_id': pick_ids and pick_ids[0] or False,
+ })
+ result.update(view_id = res and res[1] or False)
+ return result
+
+ def action_wait(self, cr, uid, ids, context=None):
+ for o in self.browse(cr, uid, ids):
+ if not o.order_line:
+ raise osv.except_osv(_('Error !'),_('You cannot confirm a sale order which has no line.'))
+ if (o.order_policy == 'manual'):
+ self.write(cr, uid, [o.id], {'state': 'manual', 'date_confirm': fields.date.context_today(self, cr, uid, context=context)})
+ else:
+ self.write(cr, uid, [o.id], {'state': 'progress', 'date_confirm': fields.date.context_today(self, cr, uid, context=context)})
+ self.pool.get('sale.order.line').button_confirm(cr, uid, [x.id for x in o.order_line])
+ self.confirm_send_note(cr, uid, ids, context)
+ return True
+
+ def action_invoice_create(self, cr, uid, ids, grouped=False, states=['confirmed', 'done', 'exception'], date_inv = False, context=None):
+ res = False
+ invoices = {}
+ invoice_ids = []
+ picking_obj = self.pool.get('stock.picking')
+ invoice = self.pool.get('account.invoice')
+ obj_sale_order_line = self.pool.get('sale.order.line')
+ partner_currency = {}
+ if context is None:
+ context = {}
+ # If date was specified, use it as date invoiced, usefull when invoices are generated this month and put the
+ # last day of the last month as invoice date
+ if date_inv:
+ context['date_inv'] = date_inv
+ for o in self.browse(cr, uid, ids, context=context):
+ currency_id = o.pricelist_id.currency_id.id
+ if (o.partner_id.id in partner_currency) and (partner_currency[o.partner_id.id] <> currency_id):
+ raise osv.except_osv(
+ _('Error !'),
+ _('You cannot group sales having different currencies for the same partner.'))
+
+ partner_currency[o.partner_id.id] = currency_id
+ lines = []
+ for line in o.order_line:
+ if line.invoiced:
+ continue
+ elif (line.state in states):
+ lines.append(line.id)
+ created_lines = obj_sale_order_line.invoice_line_create(cr, uid, lines)
+ if created_lines:
+ invoices.setdefault(o.partner_id.id, []).append((o, created_lines))
+ if not invoices:
+ for o in self.browse(cr, uid, ids, context=context):
+ for i in o.invoice_ids:
+ if i.state == 'draft':
+ return i.id
+ for val in invoices.values():
+ if grouped:
+ res = self._make_invoice(cr, uid, val[0][0], reduce(lambda x, y: x + y, [l for o, l in val], []), context=context)
+ invoice_ref = ''
+ for o, l in val:
+ invoice_ref += o.name + '|'
+ self.write(cr, uid, [o.id], {'state': 'progress'})
+ if o.order_policy == 'picking':
+ picking_obj.write(cr, uid, map(lambda x: x.id, o.picking_ids), {'invoice_state': 'invoiced'})
+ cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (o.id, res))
+ invoice.write(cr, uid, [res], {'origin': invoice_ref, 'name': invoice_ref})
+ else:
+ for order, il in val:
+ res = self._make_invoice(cr, uid, order, il, context=context)
+ invoice_ids.append(res)
+ self.write(cr, uid, [order.id], {'state': 'progress'})
+ if order.order_policy == 'picking':
+ picking_obj.write(cr, uid, map(lambda x: x.id, order.picking_ids), {'invoice_state': 'invoiced'})
+ cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (order.id, res))
+ if res:
+ self.invoice_send_note(cr, uid, ids, res, context)
+ return res
+
+ def action_cancel(self, cr, uid, ids, context=None):
+ wf_service = netsvc.LocalService("workflow")
+ if context is None:
+ context = {}
+ sale_order_line_obj = self.pool.get('sale.order.line')
+ proc_obj = self.pool.get('procurement.order')
+ for sale in self.browse(cr, uid, ids, context=context):
+ for pick in sale.picking_ids:
+ if pick.state not in ('draft', 'cancel'):
+ raise osv.except_osv(
+ _('Could not cancel sales order !'),
+ _('You must first cancel all picking attached to this sales order.'))
+ if pick.state == 'cancel':
+ for mov in pick.move_lines:
+ proc_ids = proc_obj.search(cr, uid, [('move_id', '=', mov.id)])
+ if proc_ids:
+ for proc in proc_ids:
+ wf_service.trg_validate(uid, 'procurement.order', proc, 'button_check', cr)
+ for r in self.read(cr, uid, ids, ['picking_ids']):
+ for pick in r['picking_ids']:
+ wf_service.trg_validate(uid, 'stock.picking', pick, 'button_cancel', cr)
+ return super(sale_order, self).action_cancel(cr, uid, ids, context=context)
+
+ def procurement_lines_get(self, cr, uid, ids, *args):
+ res = []
+ for order in self.browse(cr, uid, ids, context={}):
+ for line in order.order_line:
+ if line.procurement_id:
+ res.append(line.procurement_id.id)
+ return res
+
+ # if mode == 'finished':
+ # returns True if all lines are done, False otherwise
+ # if mode == 'canceled':
+ # returns True if there is at least one canceled line, False otherwise
+ def test_state(self, cr, uid, ids, mode, *args):
+ assert mode in ('finished', 'canceled'), _("invalid mode for test_state")
+ finished = True
+ canceled = False
+ notcanceled = False
+ write_done_ids = []
+ write_cancel_ids = []
+ for order in self.browse(cr, uid, ids, context={}):
+ for line in order.order_line:
+ if (not line.procurement_id) or (line.procurement_id.state=='done'):
+ if line.state != 'done':
+ write_done_ids.append(line.id)
+ else:
+ finished = False
+ if line.procurement_id:
+ if (line.procurement_id.state == 'cancel'):
+ canceled = True
+ if line.state != 'exception':
+ write_cancel_ids.append(line.id)
+ else:
+ notcanceled = True
+ if write_done_ids:
+ self.pool.get('sale.order.line').write(cr, uid, write_done_ids, {'state': 'done'})
+ if write_cancel_ids:
+ self.pool.get('sale.order.line').write(cr, uid, write_cancel_ids, {'state': 'exception'})
+
+ if mode == 'finished':
+ return finished
+ elif mode == 'canceled':
+ return canceled
+ if notcanceled:
+ return False
+ return canceled
+
+ def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, context=None):
+ return {
+ 'name': line.name.split('\n')[0],
+ 'origin': order.name,
+ 'date_planned': date_planned,
+ 'product_id': line.product_id.id,
+ 'product_qty': line.product_uom_qty,
+ 'product_uom': line.product_uom.id,
+ 'product_uos_qty': (line.product_uos and line.product_uos_qty)\
+ or line.product_uom_qty,
+ 'product_uos': (line.product_uos and line.product_uos.id)\
+ or line.product_uom.id,
+ 'location_id': order.shop_id.warehouse_id.lot_stock_id.id,
+ 'procure_method': line.type,
+ 'move_id': move_id,
+ 'company_id': order.company_id.id,
+ 'note': '\n'.join(line.name.split('\n')[1:]),
+ 'property_ids': [(6, 0, [x.id for x in line.property_ids])]
+ }
+
+ def _prepare_order_line_move(self, cr, uid, order, line, picking_id, date_planned, context=None):
+ location_id = order.shop_id.warehouse_id.lot_stock_id.id
+ output_id = order.shop_id.warehouse_id.lot_output_id.id
+ return {
+ 'name': line.name.split('\n')[0][:250],
+ 'picking_id': picking_id,
+ 'product_id': line.product_id.id,
+ 'date': date_planned,
+ 'date_expected': date_planned,
+ 'product_qty': line.product_uom_qty,
+ 'product_uom': line.product_uom.id,
+ 'product_uos_qty': (line.product_uos and line.product_uos_qty) or line.product_uom_qty,
+ 'product_uos': (line.product_uos and line.product_uos.id)\
+ or line.product_uom.id,
+ 'product_packaging': line.product_packaging.id,
+ 'partner_id': line.address_allotment_id.id or order.partner_shipping_id.id,
+ 'location_id': location_id,
+ 'location_dest_id': output_id,
+ 'sale_line_id': line.id,
+ 'tracking_id': False,
+ 'state': 'draft',
+ #'state': 'waiting',
+ 'note': '\n'.join(line.name.split('\n')[1:]),
+ 'company_id': order.company_id.id,
+ 'price_unit': line.product_id.standard_price or 0.0
+ }
+
+ def _prepare_order_picking(self, cr, uid, order, context=None):
+ pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out')
+ return {
+ 'name': pick_name,
+ 'origin': order.name,
+ 'date': order.date_order,
+ 'type': 'out',
+ 'state': 'auto',
+ 'move_type': order.picking_policy,
+ 'sale_id': order.id,
+ 'partner_id': order.partner_shipping_id.id,
+ 'note': order.note,
+ 'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none',
+ 'company_id': order.company_id.id,
+ }
+
+ def ship_recreate(self, cr, uid, order, line, move_id, proc_id):
+ # FIXME: deals with potentially cancelled shipments, seems broken (specially if shipment has production lot)
+ """
+ Define ship_recreate for process after shipping exception
+ param order: sale order to which the order lines belong
+ param line: sale order line records to procure
+ param move_id: the ID of stock move
+ param proc_id: the ID of procurement
+ """
+ move_obj = self.pool.get('stock.move')
+ if order.state == 'shipping_except':
+ for pick in order.picking_ids:
+ for move in pick.move_lines:
+ if move.state == 'cancel':
+ mov_ids = move_obj.search(cr, uid, [('state', '=', 'cancel'),('sale_line_id', '=', line.id),('picking_id', '=', pick.id)])
+ if mov_ids:
+ for mov in move_obj.browse(cr, uid, mov_ids):
+ # FIXME: the following seems broken: what if move_id doesn't exist? What if there are several mov_ids? Shouldn't that be a sum?
+ move_obj.write(cr, uid, [move_id], {'product_qty': mov.product_qty, 'product_uos_qty': mov.product_uos_qty})
+ self.pool.get('procurement.order').write(cr, uid, [proc_id], {'product_qty': mov.product_qty, 'product_uos_qty': mov.product_uos_qty})
+ return True
+
+ def _get_date_planned(self, cr, uid, order, line, start_date, context=None):
+ date_planned = datetime.strptime(start_date, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(days=line.delay or 0.0)
+ date_planned = (date_planned - timedelta(days=order.company_id.security_lead)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
+ return date_planned
+
+ def _create_pickings_and_procurements(self, cr, uid, order, order_lines, picking_id=False, context=None):
+ """Create the required procurements to supply sale order lines, also connecting
+ the procurements to appropriate stock moves in order to bring the goods to the
+ sale order's requested location.
+
+ If ``picking_id`` is provided, the stock moves will be added to it, otherwise
+ a standard outgoing picking will be created to wrap the stock moves, as returned
+ by :meth:`~._prepare_order_picking`.
+
+ Modules that wish to customize the procurements or partition the stock moves over
+ multiple stock pickings may override this method and call ``super()`` with
+ different subsets of ``order_lines`` and/or preset ``picking_id`` values.
+
+ :param browse_record order: sale order to which the order lines belong
+ :param list(browse_record) order_lines: sale order line records to procure
+ :param int picking_id: optional ID of a stock picking to which the created stock moves
+ will be added. A new picking will be created if ommitted.
+ :return: True
+ """
+ move_obj = self.pool.get('stock.move')
+ picking_obj = self.pool.get('stock.picking')
+ procurement_obj = self.pool.get('procurement.order')
+ proc_ids = []
+
+ for line in order_lines:
+ if line.state == 'done':
+ continue
+
+ date_planned = self._get_date_planned(cr, uid, order, line, order.date_order, context=context)
+
+ if line.product_id:
+ if line.product_id.product_tmpl_id.type in ('product', 'consu'):
+ if not picking_id:
+ picking_id = picking_obj.create(cr, uid, self._prepare_order_picking(cr, uid, order, context=context))
+ move_id = move_obj.create(cr, uid, self._prepare_order_line_move(cr, uid, order, line, picking_id, date_planned, context=context))
+ else:
+ # a service has no stock move
+ move_id = False
+
+ proc_id = procurement_obj.create(cr, uid, self._prepare_order_line_procurement(cr, uid, order, line, move_id, date_planned, context=context))
+ proc_ids.append(proc_id)
+ line.write({'procurement_id': proc_id})
+ self.ship_recreate(cr, uid, order, line, move_id, proc_id)
+
+ wf_service = netsvc.LocalService("workflow")
+ if picking_id:
+ wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr)
+ self.delivery_send_note(cr, uid, [order.id], picking_id, context)
+
+
+ for proc_id in proc_ids:
+ wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr)
+
+ val = {}
+ if order.state == 'shipping_except':
+ val['state'] = 'progress'
+ val['shipped'] = False
+
+ if (order.order_policy == 'manual'):
+ for line in order.order_line:
+ if (not line.invoiced) and (line.state not in ('cancel', 'draft')):
+ val['state'] = 'manual'
+ break
+ order.write(val)
+ return True
+
+ def action_ship_create(self, cr, uid, ids, context=None):
+ for order in self.browse(cr, uid, ids, context=context):
+ self._create_pickings_and_procurements(cr, uid, order, order.order_line, None, context=context)
+ return True
+
+ def action_ship_end(self, cr, uid, ids, context=None):
+ for order in self.browse(cr, uid, ids, context=context):
+ val = {'shipped': True}
+ if order.state == 'shipping_except':
+ val['state'] = 'progress'
+ if (order.order_policy == 'manual'):
+ for line in order.order_line:
+ if (not line.invoiced) and (line.state not in ('cancel', 'draft')):
+ val['state'] = 'manual'
+ break
+ for line in order.order_line:
+ towrite = []
+ if line.state == 'exception':
+ towrite.append(line.id)
+ if towrite:
+ self.pool.get('sale.order.line').write(cr, uid, towrite, {'state': 'done'}, context=context)
+ res = self.write(cr, uid, [order.id], val)
+ if res:
+ self.delivery_end_send_note(cr, uid, [order.id], context=context)
+ return True
+
+ def has_stockable_products(self, cr, uid, ids, *args):
+ for order in self.browse(cr, uid, ids):
+ for order_line in order.order_line:
+ if order_line.product_id and order_line.product_id.product_tmpl_id.type in ('product', 'consu'):
+ return True
+ return False
+ # ------------------------------------------------
+ # OpenChatter methods and notifications
+ # ------------------------------------------------
+
+ def get_needaction_user_ids(self, cr, uid, ids, context=None):
+ result = super(sale_order, self).get_needaction_user_ids(cr, uid, ids, context=context)
+ for obj in self.browse(cr, uid, ids, context=context):
+ if (obj.state == 'manual' or obj.state == 'progress'):
+ result[obj.id].append(obj.user_id.id)
+ return result
+
+ def delivery_send_note(self, cr, uid, ids, picking_id, context=None):
+ for order in self.browse(cr, uid, ids, context=context):
+ for picking in (pck for pck in order.picking_ids if pck.id == picking_id):
+ # convert datetime field to a datetime, using server format, then
+ # convert it to the user TZ and re-render it with %Z to add the timezone
+ picking_datetime = fields.DT.datetime.strptime(picking.min_date, DEFAULT_SERVER_DATETIME_FORMAT)
+ picking_date_str = fields.datetime.context_timestamp(cr, uid, picking_datetime, context=context).strftime(DATETIME_FORMATS_MAP['%+'] + " (%Z)")
+ self.message_append_note(cr, uid, [order.id], body=_("Delivery Order %sscheduled for %s.") % (picking.name, picking_date_str), context=context)
+
+ def delivery_end_send_note(self, cr, uid, ids, context=None):
+ self.message_append_note(cr, uid, ids, body=_("Order delivered."), context=context)
+
+
+class sale_order_line(osv.osv):
+
+ def _number_packages(self, cr, uid, ids, field_name, arg, context=None):
+ res = {}
+ for line in self.browse(cr, uid, ids, context=context):
+ try:
+ res[line.id] = int((line.product_uom_qty+line.product_packaging.qty-0.0001) / line.product_packaging.qty)
+ except:
+ res[line.id] = 1
+ return res
+
+ _inherit = 'sale.order.line'
+ _columns = {
+ 'delay': fields.float('Delivery Lead Time', required=True, help="Number of days between the order confirmation the shipping of the products to the customer", readonly=True, states={'draft': [('readonly', False)]}),
+ 'procurement_id': fields.many2one('procurement.order', 'Procurement'),
+ 'type': fields.selection([('make_to_stock', 'from stock'), ('make_to_order', 'on order')], 'Procurement Method', required=True, readonly=True, states={'draft': [('readonly', False)]},
+ help="If 'on order', it triggers a procurement when the sale order is confirmed to create a task, purchase order or manufacturing order linked to this sale order line."),
+ 'property_ids': fields.many2many('mrp.property', 'sale_order_line_property_rel', 'order_id', 'property_id', 'Properties', readonly=True, states={'draft': [('readonly', False)]}),
+ 'product_packaging': fields.many2one('product.packaging', 'Packaging'),
+ 'move_ids': fields.one2many('stock.move', 'sale_line_id', 'Inventory Moves', readonly=True),
+ 'number_packages': fields.function(_number_packages, type='integer', string='Number Packages'),
+
+ }
+ _defaults = {
+ 'delay': 0.0,
+ 'type': 'make_to_stock',
+ 'product_packaging': False,
+ }
+
+ def _prepare_order_line_invoice_line(self, cr, uid, line, account_id=False, context=None):
+ def _get_line_qty(line):
+ if not (line.order_id.invoice_quantity=='order') or line.procurement_id:
+ return self.pool.get('procurement.order').quantity_get(cr, uid, line.procurement_id.id, context=context)
+
+ def _get_line_uom(line):
+ if not (line.order_id.invoice_quantity=='order') or line.procurement_id:
+ return self.pool.get('procurement.order').uom_get(cr, uid, line.procurement_id.id, context=context)
+
+ return super(sale_order_line, self)._prepare_order_line_invoice_line(cr, uid, line, account_id=account_id, context=context)
+
+ def product_packaging_change(self, cr, uid, ids, pricelist, product, qty=0, uom=False,
+ partner_id=False, packaging=False, flag=False, context=None):
+ if not product:
+ return {'value': {'product_packaging': False}}
+ product_obj = self.pool.get('product.product')
+ product_uom_obj = self.pool.get('product.uom')
+ pack_obj = self.pool.get('product.packaging')
+ warning = {}
+ result = {}
+ warning_msgs = ''
+ if flag:
+ res = self.product_id_change(cr, uid, ids, pricelist=pricelist,
+ product=product, qty=qty, uom=uom, partner_id=partner_id,
+ packaging=packaging, flag=False, context=context)
+ warning_msgs = res.get('warning') and res['warning']['message']
+
+ products = product_obj.browse(cr, uid, product, context=context)
+ if not products.packaging:
+ packaging = result['product_packaging'] = False
+ elif not packaging and products.packaging and not flag:
+ packaging = products.packaging[0].id
+ result['product_packaging'] = packaging
+
+ if packaging:
+ default_uom = products.uom_id and products.uom_id.id
+ pack = pack_obj.browse(cr, uid, packaging, context=context)
+ q = product_uom_obj._compute_qty(cr, uid, uom, pack.qty, default_uom)
+# qty = qty - qty % q + q
+ if qty and (q and not (qty % q) == 0):
+ ean = pack.ean or _('(n/a)')
+ qty_pack = pack.qty
+ type_ul = pack.ul
+ if not warning_msgs:
+ warn_msg = _("You selected a quantity of %d Units.\n"
+ "But it's not compatible with the selected packaging.\n"
+ "Here is a proposition of quantities according to the packaging:\n"
+ "EAN: %s Quantity: %s Type of ul: %s") % \
+ (qty, ean, qty_pack, type_ul.name)
+ warning_msgs += _("Picking Information ! : ") + warn_msg + "\n\n"
+ warning = {
+ 'title': _('Configuration Error !'),
+ 'message': warning_msgs
+ }
+ result['product_uom_qty'] = qty
+
+ return {'value': result, 'warning': warning}
+
\ No newline at end of file
diff --git a/addons/sale_stock/sale_stock_data.xml b/addons/sale_stock/sale_stock_data.xml
new file mode 100644
index 00000000000..2957f4556fa
--- /dev/null
+++ b/addons/sale_stock/sale_stock_data.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/addons/sale_stock/sale_stock_demo.xml b/addons/sale_stock/sale_stock_demo.xml
new file mode 100644
index 00000000000..d336cd0c37e
--- /dev/null
+++ b/addons/sale_stock/sale_stock_demo.xml
@@ -0,0 +1,109 @@
+
+
+
+
+
+ manual
+
+
+
+
+
+ manual
+
+
+
+ manual
+
+
+
+ manual
+
+
+
+
+
+ picking
+ procurement
+ Invoice after delivery
+
+
+
+ make_to_stock
+
+
+
+ make_to_stock
+
+
+
+ make_to_order
+
+
+
+ make_to_order
+
+
+
+ 2
+
+
+
+ 7
+ make_to_order
+
+
+
+ 8
+ make_to_order
+
+
+
+ make_to_order
+ 1
+
+
+
+ make_to_order
+ 15
+
+
+
+ make_to_stock
+
+
+
+ 1
+ make_to_stock
+
+
+
+
+ make_to_stock
+
+
+
+ make_to_order
+ 15
+
+
+
+ make_to_order
+ 15
+
+
+
+ make_to_stock
+ 15
+
+
+
+ make_to_stock
+ 15
+
+
+
+
+
+
+
diff --git a/addons/sale_stock/sale_stock_view.xml b/addons/sale_stock/sale_stock_view.xml
new file mode 100644
index 00000000000..47a33ea0179
--- /dev/null
+++ b/addons/sale_stock/sale_stock_view.xml
@@ -0,0 +1,150 @@
+
+
+
+
+
+
+
+ sale.shop.sale.stock
+ sale.shop
+
+ tree
+
+
+
+
+
+
+
+
+
+ sale.order.tree.sale.stock
+ sale.order
+
+ tree
+
+
+
+
+
+
+
+
+ sale.order.form.sale.stock
+ sale.order
+
+ form
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ days
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/sale_stock/sale_stock_workflow.xml b/addons/sale_stock/sale_stock_workflow.xml
new file mode 100644
index 00000000000..0bea307292c
--- /dev/null
+++ b/addons/sale_stock/sale_stock_workflow.xml
@@ -0,0 +1,125 @@
+
+
+
+
+
+
+
+
+ wait_ship
+
+
+
+
+ cancel3
+ True
+ stopall
+ action_cancel()
+
+
+
+
+ ship
+ function
+ action_ship_create()
+
+
+
+
+ ship_except
+ function
+ write({'state':'shipping_except'})
+
+
+
+
+ ship_end
+ function
+ action_ship_end()
+
+
+
+
+ ship_cancel
+ True
+ stopall
+ action_cancel()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ (order_policy=='picking')
+
+
+
+
+
+ cancel
+
+
+
+
+
+ (order_policy!='prepaid') or invoiced
+
+
+
+
+
+ manual_invoice
+
+
+
+
+
+
+
+
+
+
+ procurement.order
+ procurement_lines_get()
+ test_state('finished')
+
+
+
+
+
+ test_state('canceled')
+
+
+
+
+
+
+ ship_recreate
+
+
+
+
+
+ ship_corrected
+
+
+
+
+
+ ship_cancel
+
+
+
+
diff --git a/addons/sale_stock/security/ir.model.access.csv b/addons/sale_stock/security/ir.model.access.csv
new file mode 100644
index 00000000000..c8e6f2b7342
--- /dev/null
+++ b/addons/sale_stock/security/ir.model.access.csv
@@ -0,0 +1,17 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_stock_picking_salesman,stock_picking salesman,stock.model_stock_picking,base.group_sale_salesman,1,1,1,0
+access_stock_move_salesman,stock_move salesman,stock.model_stock_move,base.group_sale_salesman,1,1,1,0
+access_stock_move_manager,stock_move manager,stock.model_stock_move,base.group_sale_manager,1,1,1,1
+access_procurement_salesman,procurement.order salesman,procurement.model_procurement_order,base.group_sale_salesman,1,1,1,0
+access_procurement_manager,procurement.order manager,procurement.model_procurement_order,base.group_sale_manager,1,1,1,1
+access_sale_order_stock_worker,sale.order stock worker,model_sale_order,stock.group_stock_user,1,1,0,0
+access_sale_order_line_stock_worker,sale.order.line stock worker,model_sale_order_line,stock.group_stock_user,1,1,0,0
+access_report_stock_move_sales,report.stock.move.sale,stock.model_report_stock_move,base.group_sale_manager,1,1,1,1
+access_stock_picking_sales,stock.picking.sales,stock.model_stock_picking,base.group_sale_manager,1,1,1,1
+access_product_packaging_user,product.packaging.user,product.model_product_packaging,base.group_sale_salesman,1,1,1,0
+access_product_packaging_manager,product.packaging.manager,product.model_product_packaging,base.group_sale_manager,1,0,0,0
+access_stock_warehouse_user,stock.warehouse.user,stock.model_stock_warehouse,base.group_sale_salesman,1,0,0,0
+access_stock_location_user,stock.location.user,stock.model_stock_location,base.group_sale_salesman,1,0,0,0
+access_product_packaging_sale_manager,product.packaging salemanager,product.model_product_packaging,base.group_sale_manager,1,1,1,1
+access_stock_warehouse_orderpoint_sale_salesman,stock.warehouse.orderpoint,procurement.model_stock_warehouse_orderpoint,base.group_sale_salesman,1,0,0,0
+access_account_move_line_salesman,account.move.line invoice,account.model_account_move_line,base.group_sale_salesman,1,0,0,0
\ No newline at end of file
diff --git a/addons/sale_stock/security/sale_stock_security.xml b/addons/sale_stock/security/sale_stock_security.xml
new file mode 100644
index 00000000000..83db390a2c4
--- /dev/null
+++ b/addons/sale_stock/security/sale_stock_security.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+ Enable Invoicing Delivery orders
+
+
+
+
+ Properties on lines
+
+
+
+
+
+
diff --git a/addons/sale/stock.py b/addons/sale_stock/stock.py
similarity index 100%
rename from addons/sale/stock.py
rename to addons/sale_stock/stock.py
diff --git a/addons/sale/stock_view.xml b/addons/sale_stock/stock_view.xml
similarity index 98%
rename from addons/sale/stock_view.xml
rename to addons/sale_stock/stock_view.xml
index 40de6872be0..6399658c392 100644
--- a/addons/sale/stock_view.xml
+++ b/addons/sale_stock/stock_view.xml
@@ -77,7 +77,7 @@
{'default_type': 'out', 'contact_display': 'partner_address', 'search_default_to_invoice': 1, 'search_default_done': 1, 'default_invoice_state': '2binvoiced'}
-
+
diff --git a/addons/sale_stock/test/cancel_order_sale_stock.yml b/addons/sale_stock/test/cancel_order_sale_stock.yml
new file mode 100644
index 00000000000..edac19ccb02
--- /dev/null
+++ b/addons/sale_stock/test/cancel_order_sale_stock.yml
@@ -0,0 +1,42 @@
+-
+ In order to test the cancel sale order.
+ First I confirm order.
+-
+ !workflow {model: sale.order, action: order_confirm, ref: sale.order5}
+-
+ Now I regenerate shipment.
+-
+ !workflow {model: sale.order, action: ship_recreate, ref: sale.order5}
+-
+ I check state of order in 'To Invoice'.
+-
+ !assert {model: sale.order, id: sale.order5, string: Sale order should be In Progress state}:
+ - state == 'manual'
+-
+ I make invoice for order.
+-
+ !workflow {model: sale.order, action: manual_invoice, ref: sale.order5}
+-
+ To cancel the sale order from Invoice Exception, I have to cancel the invoice of sale order.
+-
+ !python {model: sale.order}: |
+ import netsvc
+ invoice_ids = self.browse(cr, uid, ref("sale.order5")).invoice_ids
+ wf_service = netsvc.LocalService("workflow")
+ first_invoice_id = invoice_ids[0]
+ wf_service.trg_validate(uid, 'account.invoice', first_invoice_id.id, 'invoice_cancel', cr)
+-
+ I check order status in "Invoice Exception" and related invoice is in cancel state.
+-
+ !assert {model: sale.order, id: sale.order5, string: Sale order should be in Invoice Exception state}:
+ - state == "invoice_except", "Order should be in Invoice Exception state after cancel Invoice"
+-
+ Then I click on the Ignore Exception button.
+-
+ !workflow {model: sale.order, action: invoice_corrected, ref: sale.order5}
+
+-
+ I check state of order in 'In Progress'.
+-
+ !assert {model: sale.order, id: sale.order5, string: Sale order should be In progress state}:
+ - state == 'progress'
\ No newline at end of file
diff --git a/addons/sale/test/manual_order_policy.yml b/addons/sale_stock/test/manual_order_policy.yml
similarity index 83%
rename from addons/sale/test/manual_order_policy.yml
rename to addons/sale_stock/test/manual_order_policy.yml
index 505ab0933d0..e640a08e8bb 100644
--- a/addons/sale/test/manual_order_policy.yml
+++ b/addons/sale_stock/test/manual_order_policy.yml
@@ -1,12 +1,12 @@
-
I confirm the Quotation with "Deliver & invoice on demand".
-
- !workflow {model: sale.order, action: order_confirm, ref: order4}
+ !workflow {model: sale.order, action: order_confirm, ref: sale.order4}
-
I check that Invoice should not created.
-
!python {model: sale.order}: |
- sale_order = self.browse(cr, uid, ref("order4"))
+ sale_order = self.browse(cr, uid, ref("sale.order4"))
assert len(sale_order.invoice_ids) == False, "Invoice should not created."
assert sale_order.picking_ids, "Delivery order should be created."
-
@@ -14,28 +14,28 @@
-
!python {model: sale.advance.payment.inv}: |
ctx = context.copy()
- ctx.update({"active_model": 'sale.order', "active_ids": [ref("order4")], "active_id":ref("order4")})
- order_line = self.pool.get('sale.order.line').browse(cr, uid, ref("line7"), context=context)
+ ctx.update({"active_model": 'sale.order', "active_ids": [ref("sale.order4")], "active_id":ref("sale.order4")})
+ order_line = self.pool.get('sale.order.line').browse(cr, uid, ref("sale.line7"), context=context)
pay_id = self.create(cr, uid, {'advance_payment_method': 'fixed', 'product_id': order_line.product_id.id, 'amount': order_line.price_subtotal, 'qtty': order_line.product_uom_qty})
self.create_invoices(cr, uid, [pay_id], context=ctx)
-
I check Invoice which made advance
-
!python {model: sale.order}: |
- order = self.browse(cr, uid, ref('order4'))
+ order = self.browse(cr, uid, ref('sale.order4'))
assert order.invoice_ids, "Invoice should be created after make advance invoice."
-
I create Invoice from sale order line.
-
!python {model: sale.order.line.make.invoice}: |
ctx = context.copy()
- ctx.update({"active_model": 'sale.order.line', "active_ids": [ref("line8")], "active_id":ref("line8")})
+ ctx.update({"active_model": 'sale.order.line', "active_ids": [ref("sale.line8")], "active_id":ref("sale.line8")})
self.make_invoices(cr, uid, [], context=ctx)
-
I check Invoice which made from sale order line.
-
!python {model: sale.order.line}: |
- line = self.browse(cr, uid, ref('line8'))
+ line = self.browse(cr, uid, ref('sale.line8'))
assert line.invoiced, "Line is not invoiced."
assert line.invoice_lines, "Invoice line should be created."
-
@@ -46,7 +46,7 @@
-
!python {model: sale.make.invoice}: |
ctx = context.copy()
- ctx = ctx.update({"active_model": 'sale.order', "active_ids": [ref("order4")], "active_id":ref("order4")})
+ ctx = ctx.update({"active_model": 'sale.order', "active_ids": [ref("sale.order4")], "active_id":ref("sale.order4")})
self.make_invoices(cr, uid, [ref("sale_make_invoice_1")], context)
-
I open the Invoice.
@@ -54,7 +54,7 @@
!python {model: sale.order}: |
import netsvc
wf_service = netsvc.LocalService("workflow")
- so = self.browse(cr, uid, ref("order4"))
+ so = self.browse(cr, uid, ref("sale.order4"))
for invoice in so.invoice_ids:
wf_service.trg_validate(uid, 'account.invoice', invoice.id, 'invoice_open', cr)
-
@@ -62,7 +62,7 @@
-
!python {model: account.invoice}: |
sale_order = self.pool.get('sale.order')
- order = sale_order.browse(cr, uid, ref("order4"))
+ order = sale_order.browse(cr, uid, ref("sale.order4"))
journal_ids = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', order.company_id.id)], limit=1)
for invoice in order.invoice_ids:
invoice.pay_and_reconcile(
@@ -74,7 +74,7 @@
I check Invoice after do manual.
-
!python {model: sale.order}: |
- sale_order = self.browse(cr, uid, ref("order4"))
+ sale_order = self.browse(cr, uid, ref("sale.order4"))
assert sale_order.invoice_ids, "Invoice should be created."
assert sale_order.invoiced, "Order is not invoiced."
assert sale_order.state == 'manual', 'Order should be in Manual.'
diff --git a/addons/sale/test/picking_order_policy.yml b/addons/sale_stock/test/picking_order_policy.yml
similarity index 91%
rename from addons/sale/test/picking_order_policy.yml
rename to addons/sale_stock/test/picking_order_policy.yml
index 16caefddf1b..73d392c1b23 100644
--- a/addons/sale/test/picking_order_policy.yml
+++ b/addons/sale_stock/test/picking_order_policy.yml
@@ -3,17 +3,17 @@
-
First I check the total amount of the Quotation before Approved.
-
- !assert {model: sale.order, id: order, string: The amount of the Quotation is not correctly computed}:
+ !assert {model: sale.order, id: sale.order, string: The amount of the Quotation is not correctly computed}:
- sum([l.price_subtotal for l in order_line]) == amount_untaxed
-
I confirm the quotation with "Invoice based on deliveries" policy.
-
- !workflow {model: sale.order, action: order_confirm, ref: order}
+ !workflow {model: sale.order, action: order_confirm, ref: sale.order}
-
I check that invoice should not created before dispatch delivery.
-
!python {model: sale.order}: |
- order = self.pool.get('sale.order').browse(cr, uid, ref("order"))
+ order = self.pool.get('sale.order').browse(cr, uid, ref("sale.order"))
assert order.state == 'progress', 'Order should be in inprogress.'
assert len(order.invoice_ids) == False, "Invoice should not created."
-
@@ -23,7 +23,7 @@
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
- order = self.browse(cr, uid, ref("order"))
+ order = self.browse(cr, uid, ref("sale.order"))
for order_line in order.order_line:
procurement = order_line.procurement_id
date_planned = datetime.strptime(order.date_order, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(days=order_line.delay or 0.0)
@@ -45,7 +45,7 @@
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
- sale_order = self.browse(cr, uid, ref("order"))
+ sale_order = self.browse(cr, uid, ref("sale.order"))
assert sale_order.picking_ids, "Delivery order is not created."
for picking in sale_order.picking_ids:
assert picking.state == "auto" or "confirmed", "Delivery order should be in 'Waitting Availability' state."
@@ -77,7 +77,7 @@
Now, I dispatch delivery order.
-
!python {model: stock.partial.picking}: |
- order = self.pool.get('sale.order').browse(cr, uid, ref("order"))
+ order = self.pool.get('sale.order').browse(cr, uid, ref("sale.order"))
for pick in order.picking_ids:
data = pick.force_assign()
if data == True:
@@ -87,7 +87,7 @@
I check sale order to verify shipment.
-
!python {model: sale.order}: |
- order = self.pool.get('sale.order').browse(cr, uid, ref("order"))
+ order = self.pool.get('sale.order').browse(cr, uid, ref("sale.order"))
assert order.shipped == True, "Sale order is not Delivered."
assert order.picked_rate == 100, "Shipment progress is not 100%."
#assert order.state == 'progress', 'Order should be in inprogress.'
@@ -97,7 +97,7 @@
-
!python {model: stock.invoice.onshipping}: |
sale = self.pool.get('sale.order')
- sale_order = sale.browse(cr, uid, ref("order"))
+ sale_order = sale.browse(cr, uid, ref("sale.order"))
ship_ids = [x.id for x in sale_order.picking_ids]
wiz_id = self.create(cr, uid, {'journal_id': ref('account.sales_journal')},
{'active_ids': ship_ids, 'active_model': 'stock.picking'})
@@ -106,7 +106,7 @@
I check the invoice details after dispatched delivery.
-
!python {model: sale.order}: |
- order = self.browse(cr, uid, ref("order"))
+ order = self.browse(cr, uid, ref("sale.order"))
assert order.invoice_ids, "Invoice is not created."
ac = order.partner_id.property_account_receivable.id
journal_ids = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'sale'), ('company_id', '=', order.company_id.id)])
@@ -134,7 +134,7 @@
!python {model: sale.order}: |
import netsvc
wf_service = netsvc.LocalService("workflow")
- so = self.browse(cr, uid, ref("order"))
+ so = self.browse(cr, uid, ref("sale.order"))
for invoice in so.invoice_ids:
wf_service.trg_validate(uid, 'account.invoice', invoice.id, 'invoice_open', cr)
-
@@ -142,7 +142,7 @@
-
!python {model: account.invoice}: |
sale_order = self.pool.get('sale.order')
- order = sale_order.browse(cr, uid, ref("order"))
+ order = sale_order.browse(cr, uid, ref("sale.order"))
journal_ids = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'cash'), ('company_id', '=', order.company_id.id)], limit=1)
for invoice in order.invoice_ids:
invoice.pay_and_reconcile(
@@ -154,7 +154,7 @@
I check the order after paid invoice.
-
!python {model: sale.order}: |
- order = self.browse(cr, uid, ref("order"))
+ order = self.browse(cr, uid, ref("sale.order"))
assert order.invoiced == True, "Sale order is not invoiced."
assert order.invoiced_rate == 100, "Invoiced progress is not 100%."
assert order.state == 'done', 'Order should be in closed.'
@@ -163,7 +163,7 @@
-
!python {model: sale.order}: |
import netsvc, tools, os
- (data, format) = netsvc.LocalService('report.sale.order').create(cr, uid, [ref('order')], {}, {})
+ (data, format) = netsvc.LocalService('report.sale.order').create(cr, uid, [ref('sale.order')], {}, {})
if tools.config['test_report_directory']:
file(os.path.join(tools.config['test_report_directory'], 'sale-sale_order.'+format), 'wb+').write(data)
diff --git a/addons/sale_stock/wizard/__init__.py b/addons/sale_stock/wizard/__init__.py
new file mode 100644
index 00000000000..504e6eddbc0
--- /dev/null
+++ b/addons/sale_stock/wizard/__init__.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+import sale_make_invoice
+import sale_make_invoice_advance
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
diff --git a/addons/sale/wizard/sale_make_invoice.py b/addons/sale_stock/wizard/sale_make_invoice.py
similarity index 100%
rename from addons/sale/wizard/sale_make_invoice.py
rename to addons/sale_stock/wizard/sale_make_invoice.py
diff --git a/addons/sale/wizard/sale_make_invoice.xml b/addons/sale_stock/wizard/sale_make_invoice.xml
similarity index 100%
rename from addons/sale/wizard/sale_make_invoice.xml
rename to addons/sale_stock/wizard/sale_make_invoice.xml
diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale_stock/wizard/sale_make_invoice_advance.py
similarity index 100%
rename from addons/sale/wizard/sale_make_invoice_advance.py
rename to addons/sale_stock/wizard/sale_make_invoice_advance.py
diff --git a/addons/sale/wizard/sale_make_invoice_advance.xml b/addons/sale_stock/wizard/sale_make_invoice_advance.xml
similarity index 100%
rename from addons/sale/wizard/sale_make_invoice_advance.xml
rename to addons/sale_stock/wizard/sale_make_invoice_advance.xml