~vauxoo/addons-vauxoo/7.0-project_issue_conf-dev_luis

« back to all changes in this revision

Viewing changes to purchase_discount/purchase_discount.py

 
[MERGE] Merge to add all changes in trunk series

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import time
28
28
import openerp.netsvc as netsvc
29
 
import ir
 
29
 
30
30
from mx import DateTime
31
31
import pooler
32
32
 
45
45
        return res
46
46
 
47
47
    _columns = {
48
 
        'discount': fields.float('Discount (%)', digits=(16, 2), help="If you chose apply a discount for this way you will overide the option of calculate based on Price Lists, you will need to change again the product to update based on pricelists, this value must be between 0-100"),
49
 
        'price_unit': fields.float('Real Unit Price', required=True, digits=(16, 4), help="Price that will be used in the rest of accounting cycle"),
50
 
        'price_base': fields.float('Base Unit Price', required=True, digits=(16, 4), help="Price base taken to calc the discount, is an informative price to use it in the rest of the purchase cycle like reference for users"),
 
48
        'discount': fields.float('Discount (%)', digits=(16, 2), help="""If you
 
49
                                 chose apply a discount for this way you will
 
50
                                 overide the option of calculate based on
 
51
                                 Price Lists, you will need to change again
 
52
                                 the product to update based on pricelists,
 
53
                                 this value must be between 0-100"""),
 
54
        'price_unit': fields.float('Real Unit Price', required=True,
 
55
                                   digits=(16, 4), help="""Price that will be
 
56
                                   used in the rest of
 
57
                                   accounting cycle"""),
 
58
        'price_base': fields.float('Base Unit Price', required=True,
 
59
                                   digits=(16, 4), help="""Price base taken to
 
60
                                   calc the discount,
 
61
                                   is an informative
 
62
                                   price to use it in
 
63
                                   the rest of the
 
64
                                   purchase cycle like
 
65
                                   reference for users"""),
51
66
    }
52
67
    _defaults = {
53
68
        'discount': lambda *a: 0.0,
54
69
    }
55
70
 
56
 
    def discount_change(self, cr, uid, ids, product, discount, price_unit, product_qty, partner_id, price_base):
 
71
    def discount_change(self, cr, uid, ids, product, discount, price_unit,
 
72
                        product_qty, partner_id, price_base):
57
73
        if not product:
58
74
            return {'value': {'price_unit': 0.0, }}
59
75
        prod = self.pool.get('product.product').browse(cr, uid, product)
71
87
        return res
72
88
 
73
89
    def product_id_change(self, cr, uid, ids, pricelist, product, qty, uom,
74
 
                          partner_id, date_order=False, fiscal_position=False, date_planned=False, name=False, price_unit=False, notes=False):
 
90
                          partner_id, date_order=False, fiscal_position=False,
 
91
                          date_planned=False, name=False, price_unit=False,
 
92
                          notes=False):
75
93
        """Copied from purchase/purchase.py and modified to take discount"""
76
94
        if not pricelist:
77
95
            raise osv.except_osv(_('No Pricelist !'), _(
78
 
                'You have to select a pricelist in the purchase form !\nPlease set one before choosing a product.'))
 
96
                                                        '''You have to select a
 
97
                                                        pricelist in the
 
98
                                                        purchase form !\n
 
99
                                                        Please set one before
 
100
                                                        choosing a product.''')
 
101
                                                        )
79
102
        if not partner_id:
80
 
            raise osv.except_osv(_('No Partner!'), _(
81
 
                'You have to select a partner in the purchase form !\nPlease set one partner before choosing a product.'))
 
103
            raise osv.except_osv(_('No Partner!'), _('''You have to select a
 
104
                                                      partner in the purchase
 
105
                                                      form !\nPlease set one
 
106
                                                      partner before choosing
 
107
                                                      a product.'''))
82
108
        if not product:
83
 
            return {'value': {'price_unit': 0.0, 'name': '', 'notes': '', 'product_uom': False}, 'domain': {'product_uom': []}}
 
109
            return {'value': {'price_unit': 0.0,
 
110
                              'name': '',
 
111
                              'notes': '',
 
112
                              'product_uom': False},
 
113
                    'domain': {'product_uom': []}}
84
114
        prod = self.pool.get('product.product').browse(cr, uid, product)
85
115
        lang = False
86
116
        if partner_id:
103
133
            if s.name.id == partner_id:
104
134
                seller_delay = s.delay
105
135
                temp_qty = s.qty  # supplier _qty assigned to temp
106
 
                if qty < temp_qty:  # If the supplier quantity is greater than entered from user, set minimal.
 
136
                if qty < temp_qty:
107
137
                    qty = temp_qty
108
138
 
109
139
        price = self.pool.get(
117
147
        prod_name = prod.partner_ref
118
148
 
119
149
        res = {
120
 
            'value': {'price_unit': price, 'price_base': price, 'name': prod_name, 'taxes_id': map(lambda x: x.id, prod.supplier_taxes_id),
121
 
            'date_planned': dt, 'notes': prod.description_purchase,
122
 
            'product_qty': qty,
123
 
            'product_uom': uom}}
 
150
            'value': {'price_unit': price,
 
151
                      'price_base': price,
 
152
                      'name': prod_name,
 
153
                      'taxes_id': map(lambda x: x.id, prod.supplier_taxes_id),
 
154
                      'date_planned': dt,
 
155
                      'notes': prod.description_purchase,
 
156
                      'product_qty': qty,
 
157
                      'product_uom': uom}}
124
158
        domain = {}
125
159
 
126
160
        partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
127
161
        taxes = self.pool.get('account.tax').browse(
128
162
            cr, uid, map(lambda x: x.id, prod.supplier_taxes_id))
129
163
        fpos = fiscal_position and self.pool.get(
130
 
            'account.fiscal.position').browse(cr, uid, fiscal_position) or False
 
164
            'account.fiscal.position').browse(cr, uid, fiscal_position) or \
 
165
                    False
131
166
        res['value']['taxes_id'] = self.pool.get(
132
167
            'account.fiscal.position').map_tax(cr, uid, fpos, taxes)
133
168
 
137
172
        domain = {'product_uom': [(
138
173
            'category_id', '=', res2[0]['category_id'][0])]}
139
174
        if res2[0]['category_id'][0] != res3:
140
 
            raise osv.except_osv(_('Wrong Product UOM !'), _(
141
 
                'You have to select a product UOM in the same category than the purchase UOM of the product'))
 
175
            raise osv.except_osv(_('Wrong Product UOM !'), _('''You have to
 
176
                                                             select a product
 
177
                                                             UOM in the same
 
178
                                                             category than the
 
179
                                                             purchase UOM of
 
180
                                                             the product'''))
142
181
 
143
182
        res['domain'] = domain
144
183
        return res
145
184
 
146
185
 
147
 
 
148
186
class purchase_order(osv.Model):
149
187
    _name = "purchase.order"
150
188
    _inherit = "purchase.order"
152
190
    def _get_order(self, cr, uid, ids, context={}):
153
191
        """Copied from purchase/purchase.py"""
154
192
        result = {}
155
 
        for line in self.pool.get('purchase.order.line').browse(cr, uid, ids, context=context):
 
193
        for line in self.pool.get('purchase.order.line').browse(cr, uid,
 
194
                                                                ids, context):
156
195
            result[line.order_id.id] = True
157
196
        return result.keys()
158
197
 
163
202
        return res
164
203
 
165
204
 
166
 
 
167
205
class stock_picking(osv.Model):
168
206
    _inherit = 'stock.picking'
169
207
 
175
213
        return discount
176
214
 
177
215
 
178
 
 
179
216
class account_invoice_line(osv.Model):
180
217
    _inherit = 'account.invoice.line'
181
218
 
194
231
        return res
195
232
 
196
233
    _columns = {
197
 
        'price_wd': fields.function(_get_price_wd, method=True, string='Price With Discount', store=True, type="float", digits=(16, 4)),
 
234
        'price_wd': fields.function(_get_price_wd, method=True,
 
235
                                    string='Price With Discount',
 
236
                                    store=True, type="float", digits=(16, 4)),
198
237
    }
199
238
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: