Skip to content

Commit

Permalink
Some changes from Guewen's review
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro M. Baeza committed Jun 20, 2014
1 parent 3ee97c0 commit 5f3f0bc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 27 deletions.
3 changes: 1 addition & 2 deletions purchase_discount/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import purchase_discount
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
from . import models
6 changes: 5 additions & 1 deletion purchase_discount/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
{
"name": "Purchase order lines with discounts",
"author": "Tiny, Acysos S.L.",
"description": """It allows to define a discount per line in the purchase
"description": """
It allows to define a discount per line in the purchase
orders. This discount can be also negative, interpreting it as an increment.
**REMARK**: This module can be incompatible with other modules that modify
purchase prices, because it overwrites computation methods.
**Contributors**:
* Pedro Manuel Baeza <[email protected]>
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import openerp.addons.decimal_precision as dp


class purchase_order_line(orm.Model):
class PurchaseOrderLine(orm.Model):
_inherit = "purchase.order.line"

def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
Expand All @@ -40,7 +40,7 @@ def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
return res

_columns = {
'discount': fields.float('Discount (%)', digits=(16, 2)),
'discount': fields.float('Discount (%)', dp.get_precision('Discount'),
'price_subtotal': fields.function(
_amount_line, string='Subtotal',
digits_compute=dp.get_precision('Account')),
Expand All @@ -56,7 +56,7 @@ def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
]


class purchase_order(orm.Model):
class PurchaseOrder(orm.Model):
_inherit = "purchase.order"

def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
Expand Down Expand Up @@ -86,10 +86,10 @@ def _amount_all(self, cr, uid, ids, field_name, arg, context=None):

def _prepare_inv_line(self, cr, uid, account_id, order_line,
context=None):
result = super(purchase_order, self)._prepare_inv_line(cr, uid,
account_id,
order_line,
context)
result = super(PurchaseOrder, self)._prepare_inv_line(cr, uid,
account_id,
order_line,
context)
result['discount'] = order_line.discount or 0.0
return result

Expand All @@ -102,37 +102,34 @@ def _get_order(self, cr, uid, ids, context=None):

_columns = {
'amount_untaxed': fields.function(
_amount_all, method=True,
digits_compute=dp.get_precision('Account'),
_amount_all, digits_compute=dp.get_precision('Account'),
string='Untaxed Amount',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The amount without tax"),
'amount_tax': fields.function(
_amount_all, method=True,
digits_compute=dp.get_precision('Account'), string='Taxes',
_amount_all, digits_compute=dp.get_precision('Account'),
string='Taxes',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The tax amount"),
'amount_total': fields.function(
_amount_all, method=True,
digits_compute=dp.get_precision('Account'), string='Total',
_amount_all, digits_compute=dp.get_precision('Account'),
string='Total',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The total amount"),
}


class stock_picking(orm.Model):
class StockPicking(orm.Model):
_inherit = 'stock.picking'

def _invoice_line_hook(self, cr, uid, move_line, invoice_line_id):
if move_line.purchase_line_id:
line = {'discount': move_line.purchase_line_id.discount}
self.pool['account.invoice.line'].write(cr, uid,
[invoice_line_id], line)
return super(stock_picking, self)._invoice_line_hook(cr, uid,
move_line,
invoice_line_id)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
return super(StockPicking, self)._invoice_line_hook(cr, uid,
move_line,
invoice_line_id)
2 changes: 1 addition & 1 deletion purchase_discount/report/order.rml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
<para style="terp_default_Right_9">[[ formatLang(line.price_unit, digits=get_digits(dp='Account') ) ]]</para>
</td>
<td>
<para style="terp_default_Right_9">[[ '%.2f'%line.discount ]]</para>
<para style="terp_default_Right_9">[[ formatLang(line.discount, digits=get_digits(dp='Discount')) ]]</para>
</td>
<td>
<para style="terp_default_Right_9">[[ formatLang(line.price_subtotal, digits=get_digits(dp='Account') ) ]] [[ o.pricelist_id.currency_id.symbol ]]</para>
Expand Down
Binary file modified purchase_discount/report/order.sxw
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<record id="invoice_supplier_form_discount" model="ir.ui.view">
<field name="name">account.invoice.supplier.form.discount</field>
<field name="model">account.invoice</field>
<field name="type">form</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<field name="price_unit" position="after">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<record model="ir.ui.view" id="purchase_discount_order_line_form">
<field name="name">purchase_discount.order.line.form</field>
<field name="model">purchase.order.line</field>
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_line_form"/>
<field name="arch" type="xml">
<field name="price_unit" position="after">
Expand All @@ -14,7 +13,6 @@
<record model="ir.ui.view" id="purchase_discount_order_line_tree">
<field name="name">purchase_discount.order.line.tree</field>
<field name="model">purchase.order.line</field>
<field name="type">tree</field>
<field name="inherit_id" ref="purchase.purchase_order_line_tree"/>
<field name="arch" type="xml">
<field name="price_unit" position="after">
Expand All @@ -26,7 +24,6 @@
<record model="ir.ui.view" id="purchase_discount_order_form">
<field name="name">purchase.discount.order.form</field>
<field name="model">purchase.order</field>
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree/field[@name='price_unit']" position="after">
Expand Down

0 comments on commit 5f3f0bc

Please sign in to comment.