~tempo-openerp/+junk/axima_stock

« back to all changes in this revision

Viewing changes to sale_margin.py

  • Committer: vg at tempo-consulting
  • Date: 2014-08-20 08:00:08 UTC
  • mto: This revision was merged to the branch mainline in revision 220.
  • Revision ID: vg@tempo-consulting.fr-20140820080008-djl013tdwybh6n6r
AX-64 [IMP] marge impactée par remise globale: montant marge défalqué de la remise globale, taux de marge basé sur montant ht + remise

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
        result = {}
73
73
        for sale in self.browse(cr, uid, ids, context=context):
74
74
            sale_price = sale.amount_untaxed or 0.0
 
75
            # remise global, calcul du taux de marge ce fait sur le
 
76
            # total ht non remisé
 
77
            # (par contre la marge brute (montant) déduit la remise globale)
 
78
            if sale.global_discount and sale.global_discount > 0.:
 
79
                sale_price += sale.global_discount
75
80
            if sale_price == 0.0:
76
81
                result[sale.id] = 0.0
77
82
            else:
84
89
            result[sale.id] = 0.0
85
90
            for line in sale.order_line:
86
91
                result[sale.id] += line.margin or 0.0
 
92
            # deduire la remise globale éventuelle de la marge
 
93
            if sale.global_discount and sale.global_discount > 0.:
 
94
                result[sale.id] -= sale.global_discount
87
95
        return result
88
96
 
89
97
    def _get_order(self, cr, uid, ids, context=None):
115
123
        'margin': fields.function(_product_margin, string='Margin', help="It gives profitability by calculating the difference between the Unit Price and the cost price.",
116
124
            store={
117
125
                'sale.order.line': (_get_order, ['order_id', 'margin'], 20),  # AX-23: trigger de order_id le module nan_product_pack writtant directement des sale.order.line associé à un order_id
118
 
                'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 20),
 
126
                'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line', 'global_discount'], 20),
119
127
            }),
120
128
        'kg': fields.function(_get_kg, type='float',
121
129
            string='KG', help=u"Coefficient Somme(prix vente) / Somme(prix achat)",