Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port 7.0 add last sale price yvr #14

Merged
merged 8 commits into from
Sep 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ python:
- "2.7"

env:
- VERSION="7.0" ODOO_REPO="odoo/odoo"
- VERSION="7.0" ODOO_REPO="OCA/OCB"
# exclude tests of modules which doesn't depends on sale_stock
- VERSION="7.0" ODOO_REPO="odoo/odoo" EXCLUDE="last_sale_price"
- VERSION="7.0" ODOO_REPO="odoo/odoo" INCLUDE="last_sale_price"

- VERSION="7.0" ODOO_REPO="OCA/OCB" EXCLUDE="last_sale_price"
- VERSION="7.0" ODOO_REPO="OCA/OCB" INCLUDE="last_sale_price"

virtualenv:
system_site_packages: true
Expand Down
21 changes: 21 additions & 0 deletions last_sale_price/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2014 Camptocamp SA
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import sale
52 changes: 52 additions & 0 deletions last_sale_price/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2014 Camptocamp SA
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{'name': 'Last Sale Price',
'summary': 'Show last price defined for customer on sale order line',
'version': '1.0',
'category': 'Sales',
'description': """
Last Sale Price
===============

Add price, quantity and date of a product of the last time it was sold to
a partner.

In order to let the salesman know if a customer already ordered a product.
And to give him hint about what price he should propose.
That information is shown next to the price in Sale Order's line Form.

Only Sale Orders' lines in state Confirmed and Done are considered to
compute those fields.

If multiple Sale Order lines for the same partner where made on the same
date for the same product, the sum of all quantity and the average price
will be displayed.
""",
'author': 'Camptocamp',
'maintainer': 'Camptocamp',
'website': 'http://www.camptocamp.com/',
'depends': ['base', 'sale'],
'data': ['sale_view.xml'],
'test': ['test/last_sale_price.yml'],
'installable': True,
'auto_install': False,
'application': False,
}
43 changes: 43 additions & 0 deletions last_sale_price/i18n/last_sale_price.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * last_sale_price
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-06-18 15:28+0000\n"
"PO-Revision-Date: 2014-06-18 15:28+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: last_sale_price:
#: field:sale.order.line,last_sale_date:0
msgid "Last Sale Date"
msgstr ""

#. module: last_sale_price
#: field:sale.order.line,last_sale_price:0
msgid "Last Sale Price"
msgstr ""

#. module: last_sale_price
#: field:sale.order.line,last_sale_qty:0
msgid "Last Sale Quantity"
msgstr ""

#. module: last_sale_price
#: model:ir.model,name:last_sale_price.model_sale_order_line
msgid "Sale Order line"
msgstr ""

#. module: last_sale_price
#: code:_description:0
#, python-format
msgid "Sales Order Line"
msgstr ""

96 changes: 96 additions & 0 deletions last_sale_price/sale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Yannick Vaucher
# Copyright 2014 Camptocamp SA
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm, fields


class SaleOrderLine(orm.Model):
_inherit = 'sale.order.line'

def _get_last_sale_sums(self, cr, uid, last_lines, context=None):
""" Get last price from sale order lines

If multiple lines exists at the same date we do an average
"""
if len(last_lines) == 1:
return last_lines[0].price_unit, last_lines[0].product_uom_qty
else:
sum_price = 0.0
sum_qty = 0.0
for line in last_lines:
sum_qty += line.product_uom_qty
sum_price += line.price_unit * line.product_uom_qty
if sum_qty == 0:
return 0
return sum_price / float(sum_qty), sum_qty

def _get_last_sale(self, cr, uid, ids, field_name, arg, context=None):
""" Get last sale price and last sale date
"""
res = {}
for res_id in ids:
res[res_id] = {'last_sale_price': False,
'last_sale_qty': False,
'last_sale_date': False}
for line in self.browse(cr, uid, ids, context=context):
if not line.product_id:
continue

line_ids = self.search(
cr, uid,
[('order_partner_id', '=', line.order_partner_id.id),
('product_id', '=', line.product_id.id),
('state', 'in', ['confirmed', 'done'])],
context=context)

if not line_ids:
continue

old_lines = self.browse(cr, uid, line_ids, context=context)
old_lines.sort(key=lambda l: l.order_id.date_order, reverse=True)

last_date = old_lines[0].order_id.date_order
last_lines = [l for l in old_lines
if l.order_id.date_order == last_date]
res[line.id]['last_sale_date'] = last_date

(last_price, last_qty) = self._get_last_sale_sums(
cr, uid, last_lines, context=context)
res[line.id]['last_sale_price'] = last_price
res[line.id]['last_sale_qty'] = last_qty
return res

_columns = {
'last_sale_price': fields.function(
_get_last_sale,
type="float",
string='Last Sale Price',
multi='last_sale'),
'last_sale_qty': fields.function(
_get_last_sale,
type="float",
string='Last Sale Quantity',
multi='last_sale'),
'last_sale_date': fields.function(
_get_last_sale,
type="date",
string='Last Sale Date',
multi='last_sale'),
}
23 changes: 23 additions & 0 deletions last_sale_price/sale_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_order_form" model="ir.ui.view">
<field name="name">sale.order.form.last_sale</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/form//field[@name='price_unit']" position="after">
<field name="last_sale_date"/>
<field name="last_sale_price"/>
<field name="last_sale_qty"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree//field[@name='price_unit']" position="after">
<field name="last_sale_date"/>
<field name="last_sale_price"/>
<field name="last_sale_qty"/>
</xpath>
</field>
</record>

</data>
</openerp>
Loading