Exemple #1
0
class AccountMove(osv.Model):
    _inherit = "account.move"

    """example of query that get these fields ---
    select sum(credit), sum(debit)
    from account_move_line
    where move_id=27
    """

    def _sum_credit_debit(self, cr, uid, ids, field, arg, context=None):
        suma = []
        dict = {}
        for id in ids:
            cr.execute("""select sum(credit), sum(debit)
                        from account_move_line
                        where move_id=%s""", (id,))
            suma = cr.fetchone()
            dict[id] = {field[0]: suma[0], field[1]: suma[1]}
        return dict  # {25:{total_debit:1200},{total_credit:1200}}

    _columns = {
        'total_debit': fields.function(_sum_credit_debit,
                                       string='Total debit', method=True,
                                       digits_compute=dp.get_precision(
                                           'Account'),
                                       type='float', multi="total_credit_debit"),
        'total_credit': fields.function(_sum_credit_debit,
                                        string='Total credit', method=True,
                                        digits_compute=dp.get_precision(
                                            'Account'),
                                        type='float', multi="total_credit_debit"),
    }
Exemple #2
0
class stock_to_date_line(osv.osv_memory):
    _name = 'stock.to.date.line'
    _description = 'Lines of stock to date'
    _order = 'date asc'

    _columns = {
        'stock_to_date_id':
        fields.many2one('stock.to.date', 'Stock To Date'),
        'date':
        fields.date('Date'),
        'virtual_available':
        fields.float('Virtual',
                     digits_compute=dp.get_precision('Product UoM')),
        'incoming_qty':
        fields.float('Incoming',
                     digits_compute=dp.get_precision('Product UoM')),
        'outgoing_qty':
        fields.float('Outgoing',
                     digits_compute=dp.get_precision('Product UoM')),
        'color':
        fields.boolean('Color', help='Just for show color in today'),
        'empty':
        fields.char(' ', size=1),
    }

    _defaults = {
        'color': False,
    }
class mrp_indicators_overweight_summary(orm.Model):
    _name = 'mrp.indicators.overweight.summary'
    _columns = {
        'name':
        fields.char('Name', size=255, required=True),
        'workcenter_id':
        fields.many2one('mrp.workcenter', 'Workcenter'),
        'qty_nominal':
        fields.float(
            'Qty nominal',
            digits_compute=dp.get_precision('Product Unit of Measure')),
        'qty_consumed':
        fields.float(
            'Qty consumed',
            digits_compute=dp.get_precision('Product Unit of Measure')),
        'overweight':
        fields.float('Overweight (%)'),
        'overweight_abs':
        fields.float('Overweight Abs'),
        'indicator_id':
        fields.many2one('mrp.indicators.overweight',
                        'Indicator',
                        ondelete='cascade',
                        required=True)
    }
Exemple #4
0
class baremo_discount(osv.Model):
    """
    OpenERP Model : baremo_discount
    """

    _name = 'baremo.discount'
    _order = "porc_disc asc"
    _columns = {
        'name':
        fields.char('Nombre',
                    size=64,
                    required=False,
                    readonly=False,
                    help="No Usado"),
        'porc_disc':
        fields.float('% Dcto',
                     digits_compute=dp.get_precision('Commission'),
                     help="% de Descuento por producto",
                     required=True),
        'porc_com':
        fields.float('% Com.',
                     digits_compute=dp.get_precision('Commission'),
                     help="% de Comision @ porcentaje Descuento",
                     required=True),
        'disc_id':
        fields.many2one('baremo', 'Baremo', required=False),
    }
    _defaults = {
        'name': lambda *a: None,
    }
Exemple #5
0
class MrpVariationFinishedProduct(osv.Model):
    _name = 'mrp.variation.finished.product'
    _rec_name = 'product_id'

    def _get_variation_cost(self, cr, uid, ids, field_name, args, context={}):
        res = {}
        for variation in self.browse(cr, uid, ids, context=context):
            res[variation.id] = variation.quantity * \
                variation.product_id.standard_price
        return res

    _columns = {
        'product_id':
        fields.many2one('product.product', 'Product'),
        'quantity':
        fields.float('Quantity',
                     digits_compute=dp.get_precision('Product UoM')),
        'production_id':
        fields.many2one('mrp.production', 'production'),
        'product_uom':
        fields.many2one('product.uom', 'UoM'),
        'cost_variation':
        fields.function(_get_variation_cost,
                        type='float',
                        digits_compute=dp.get_precision('Purchase Price'),
                        string='Variation Cost')
    }
class recover_components_composition(orm.TransientModel):

    _name = 'recover.components.composition'
    _columns = {
        'product_id':
        fields.many2one('product.product', 'Product'),
        'qty_available':
        fields.float(
            'Qty available',
            digits_compute=dp.get_precision('Product Unit of Measure')),
        'qty_recover':
        fields.float(
            'Qty recover',
            digits_compute=dp.get_precision('Product Unit of Measure')),
        'product_uom':
        fields.many2one('product.uom', 'UoM'),
        'recover_prodlot_id':
        fields.many2one('stock.production.lot', 'Recover Lot'),
        'location_dest_id':
        fields.many2one('stock.location', 'Location dest.'),
        'recover':
        fields.boolean('Recover'),
        'parent_id':
        fields.many2one('recover.components', 'Recover components')
    }
Exemple #7
0
class SalesmanCommissionPaymentLine(osv.Model):
    _name = 'salesman.commission.payment.line'
    _columns = {
        'commission_id': fields.many2one('salesman.commission.payment',
                                         'Commission Lines', required=True),
        'date_effective': fields.date('Effective of the Payment',
                                      required=True),
        'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year',
                                         required=True, states={'draft': [('readonly', False)]}),
        'period_id': fields.many2one('account.period', 'Period', required=True,
                                     select=2),
        'partner_id': fields.many2one('res.partner', 'Partner Ref.'),
        'ref': fields.char('Ref.', size=32),
        'name': fields.char('Name', size=64, required=True),
        'journal_id': fields.many2one('account.journal', 'Journal',
                                      required=True, select=1),
        'debit': fields.float('Debit', digits=(16, 2)),
        'commission_rate': fields.float('Rate(%)',
                                        digits_compute=dp.get_precision('Commission'), readonly=True),
        'commissioned_amount_line': fields.float('Commission',
                                                 digits_compute=dp.get_precision('Commission'), readonly=True),
        'user_id': fields.many2one('res.users', 'Salesman', required=True,
                                   states={'draft': [('readonly', False)]}),
        'commission_paid': fields.boolean('Paid Commission'),
    }
Exemple #8
0
class ProductPackaging(models.Model):
    _inherit = 'product.packaging'

    list_price = fields.Float(
        string='Package Price',
        digits_compute=dp.get_precision('Product Price'),
        help="This price will be considered as a price for complete package")
    package_material_id = fields.Many2one(
        comodel_name='product.packaging.material', string='Package Material')
    weight = fields.Float(
        string='Package Weight',
        digits_compute=dp.get_precision('Stock Weight'),
        help="Weight of the package itself, wighout counting inner products.")

    @api.onchange('list_price', 'qty')
    def _onchange_list_price(self):
        price_precision = self.env['decimal.precision'].precision_get(
            'Product Price')
        if self.qty:
            price_computed = (
                round(self.list_price / self.qty, price_precision) * self.qty)
        else:
            price_computed = 0.0
        if str(self.list_price) != str(price_computed):
            return {
                'warning': {
                    'title':
                    _('Problem with price'),
                    'message':
                    _("With the current decimal precision, you can't get "
                      "this price. (Approx. price suggested: %s)") %
                    str(price_computed)
                }
            }
class account_invoice_simulation_detail_(osv.osv_memory):
    """ Account Invoice Simulation Line"""

    _name = 'account.invoice.simulation.detail_'
    _description = 'Sale Order Simulation Payments Detail _'

    _columns = {
        'order_id':
        fields.many2one('invoice.readjustment',
                        'Order Reference',
                        required=True),
        'name':
        fields.text('Description'),
        'date':
        fields.date('Fecha'),
        'monthly_amount':
        fields.float('Pago Mensual',
                     required=True,
                     digits_compute=dp.get_precision('Account')),
        'initial_balance':
        fields.float('Saldo Inicial',
                     required=True,
                     digits_compute=dp.get_precision('Account')),
        'ending_balance':
        fields.float('Saldo Final',
                     required=True,
                     digits_compute=dp.get_precision('Account')),
        'sequence':
        fields.integer('Sequence'),
    }
Exemple #10
0
class ResCurrency(osv.Model):

    def _current_rate(self, cr, uid, ids, name, arg, context=None):
        if context is None:
            context = {}
        res = {}
        if 'date' in context:
            date = context['date']
        else:
            date = time.strftime('%Y-%m-%d')
        date = date or time.strftime('%Y-%m-%d')
        for id in ids:
            cr.execute(
                "SELECT currency_id, rate\
                    FROM res_currency_rate\
                WHERE currency_id = %s\
                AND name <= %s\
                ORDER BY name desc LIMIT 1", (id, date))
            if cr.rowcount:
                id, rate = cr.fetchall()[0]
                res[id] = rate
            else:
                res[id] = 0
        return res

    _inherit = "res.currency"
    _columns = {
        'rate': fields.function(_current_rate, method=True,
            string='Current Rate', digits_compute=dp.get_precision('Currency'),
            help='The rate of the currency to the currency of rate 1'),
        'rounding': fields.float('Rounding factor',
            digits_compute=dp.get_precision('Currency')),

    }
Exemple #11
0
class StockPicking(models.Model):
    _inherit = 'stock.picking'

    @api.one
    @api.depends('sale_id.amount_untaxed', 'sale_id.amount_tax',
                 'sale_id.amount_total')
    def _compute_amount(self):
        if self.sale_id:
            if self.pack_operation_ids:
                for operation in self.pack_operation_ids:
                    self.amount_untaxed += operation.sale_subtotal
                    self.amount_tax += operation.sale_taxes
                self.amount_total = self.amount_untaxed + self.amount_tax
            else:
                for move in self.move_lines:
                    self.amount_untaxed += move.sale_subtotal
                    self.amount_tax += move.sale_taxes
                self.amount_total = self.amount_untaxed + self.amount_tax

    amount_untaxed = fields.Float(compute='_compute_amount',
                                  digits_compute=dp.get_precision('Account'),
                                  string='Untaxed Amount')
    amount_tax = fields.Float(compute='_compute_amount',
                              digits_compute=dp.get_precision('Account'),
                              string='Taxes')
    amount_total = fields.Float(compute='_compute_amount',
                                digits_compute=dp.get_precision('Account'),
                                string='Total')
    stock_valued = fields.Boolean(string="Stock Valued")
Exemple #12
0
class annexure_2b_report(osv.osv):
    _name = "annexure.2b.report"
    _description = "Annexure 2B Report"
    _auto = False

    _columns = {
        'id': fields.integer('ID'),
        'account_id': fields.many2one('account.account', 'Tax Account'),
        'invoice_id': fields.many2one('account.invoice', 'Invoice'),
        'partner_id': fields.many2one('res.partner', 'Partner'),
        'tin_no': fields.char('Tin No.', size=64),
        'date':fields.date('Date'),
        'base': fields.float('Base', digits_compute=dp.get_precision('Account')),
        'amount': fields.float('Amount', digits_compute=dp.get_precision('Account')),
        'base_code_id': fields.many2one('account.tax.code', 'Base Code'),
        'base_amount': fields.float('Base Code Amount', digits_compute=dp.get_precision('Account')),
        'tax_code_id': fields.many2one('account.tax.code', 'Tax Code'),
        'tax_amount': fields.float('Tax Code Amount', digits_compute=dp.get_precision('Account')),
    }

    def init(self, cr):
        tools.drop_view_if_exists(cr, 'annexure_2b_report')
        cr.execute("""CREATE OR REPLACE view annexure_2b_report AS (
            select
                row_number() OVER () AS id,
                ai.date_invoice AS date,
                ai.partner_id as partner_id,
                rp.tin_no as tin_no,
                ait.invoice_id as invoice_id,
                ait.account_id as account_id,
                ait.base as base,
                ait.amount as amount,
                ait.base_code_id as base_code_id,
                ait.base_amount as base_amount,
                ait.tax_code_id as tax_code_id,
                ait.tax_amount as tax_amount

            FROM 
                account_invoice_line ail
                LEFT JOIN account_invoice ai ON (ail.invoice_id = ai.id)
                LEFT JOIN account_invoice_tax ait ON (ait.invoice_id = ai.id)
                LEFT JOIN res_partner rp ON (ai.partner_id = rp.id)

                WHERE ai.type = 'out_invoice'
                GROUP BY ail.id,
                ai.date_invoice,
                ai.partner_id,
                rp.tin_no,
                ail.account_id,
                ait.invoice_id,
                ait.account_id,
                ait.base,
                ait.amount,
                ait.base_amount,
                ait.tax_amount,
                ait.base_code_id,
                ait.tax_code_id
                )""")
Exemple #13
0
class policy_line_ot(osv.Model):

    _name = 'hr.policy.line.ot'

    def _tz_list(self, cr, uid, context=None):

        res = tuple()
        for name in common_timezones:
            res += ((name, name), )
        return res

    _columns = {
        'name':
        fields.char('Name', size=64, required=True),
        'policy_id':
        fields.many2one('hr.policy.ot', 'Policy'),
        'type':
        fields.selection([('daily', 'Daily'), ('weekly', 'Weekly'),
                          ('restday', 'Rest Day'),
                          ('holiday', 'Public Holiday')],
                         'Type',
                         required=True),
        'weekly_working_days':
        fields.integer('Weekly Working Days'),
        'active_after':
        fields.integer('Active After',
                       help="Minutes after which this policy applies"),
        'active_start_time':
        fields.char('Active Start Time',
                    size=5,
                    help="Time in 24 hour time format"),
        'active_end_time':
        fields.char('Active End Time',
                    size=5,
                    help="Time in 24 hour time format"),
        'tz':
        fields.selection(_tz_list, 'Time Zone'),
        'rate':
        fields.float('Rate',
                     required=True,
                     help='Multiplier of employee wage.'),
        'accrual_policy_line_id':
        fields.many2one('hr.policy.line.accrual', 'Accrual Policy Line'),
        'accrual_rate':
        fields.float('Accrual Rate',
                     digits_compute=dp.get_precision('Accruals')),
        'accrual_min':
        fields.float('Minimum Accrual',
                     digits_compute=dp.get_precision('Accruals')),
        'accrual_max':
        fields.float('Maximum Accrual',
                     digits_compute=dp.get_precision('Accruals')),
        'code':
        fields.char('Code',
                    required=True,
                    help="Use this code in the salary rules.")
    }
Exemple #14
0
class mrp_production_workcenter_line(models.Model):

    _inherit = 'mrp.production.workcenter.line'

    est_prod_cost = fields.Float(string="Est. prod. cost",
                                 digits=dp.get_precision('Product costing'))
    prod_cost = fields.Float(string="Production cost",
                             digits=dp.get_precision('Product costing'))
    est_hour = fields.Float(string="Est. time",
                            help="Estimated operation duration.",
                            digits=(4, 9))
class mrp_indicators_oee_line(orm.Model):
    _name = 'mrp.indicators.oee.line'
    _columns = {
        'name':
        fields.char('Name', size=255, required=True),
        'date':
        fields.date('Date'),
        'workcenter_id':
        fields.many2one('mrp.workcenter', 'Workcenter'),
        'production_id':
        fields.many2one('mrp.production', 'Production', select=True),
        'qty':
        fields.float(
            'Qty',
            digits_compute=dp.get_precision('Product Unit of Measure'),
            required=True),
        'qty_scraps':
        fields.float(
            'Scraps',
            digits_compute=dp.get_precision('Product Unit of Measure')),
        'qty_good':
        fields.float(
            'Real qty',
            digits_compute=dp.get_precision('Product Unit of Measure')),
        'product_id':
        fields.many2one('product.product', 'Product', required=True),
        'stop_time':
        fields.float('Stop time'),
        'real_time':
        fields.float('Real time'),
        'tic_time':
        fields.float('TiC time'),
        'time_start':
        fields.float('Time start'),
        'time_stop':
        fields.float('Time stop'),
        'gasoleo_start':
        fields.float('Gasoleo start'),
        'gasoleo_stop':
        fields.float('Gasoleo stop'),
        'oee':
        fields.float('OEE'),
        'availability':
        fields.float('Availability'),
        'performance':
        fields.float('Performance'),
        'quality':
        fields.float('Quality'),
        'indicator_id':
        fields.many2one('mrp.indicators.oee',
                        'Indicator',
                        ondelete='cascade',
                        required=True)
    }
Exemple #16
0
class stock_move(models.Model):

    _inherit = "stock.move"

    price_subtotal = fields.Float(
        compute='_get_subtotal',
        string="Subtotal",
        digits_compute=dp.get_precision('Sale Price'),
        readonly=True,
        store=True)
    order_price_unit = fields.Float(
        compute='_get_subtotal',
        string="Price unit",
        digits_compute=dp.get_precision('Sale Price'),
        readonly=True,
        store=True)
    cost_subtotal = fields.Float(compute='_get_subtotal',
                                 string="Cost subtotal",
                                 digits_compute=dp.get_precision('Sale Price'),
                                 readonly=True,
                                 store=True)
    margin = fields.Float(compute='_get_subtotal',
                          string="Margin",
                          digits_compute=dp.get_precision('Sale Price'),
                          readonly=True,
                          store=True)
    percent_margin = fields.Float(
        compute='_get_subtotal',
        string="% margin",
        digits_compute=dp.get_precision('Sale Price'),
        readonly=True,
        store=True)

    @api.multi
    @api.depends('product_id', 'product_qty', 'procurement_id.sale_line_id')
    def _get_subtotal(self):
        for move in self:
            if move.procurement_id.sale_line_id:
                cost_price = move.product_id.standard_price or 0.0
                price_unit = (
                    move.procurement_id.sale_line_id.price_unit *
                    (1 - (move.procurement_id.sale_line_id.discount or 0.0) /
                     100.0))
                move.price_subtotal = price_unit * move.product_qty
                move.order_price_unit = price_unit
                move.cost_subtotal = cost_price * move.product_qty
                move.margin = move.price_subtotal - move.cost_subtotal
                if move.price_subtotal > 0:
                    move.percent_margin = (move.margin /
                                           move.price_subtotal) * 100
                else:
                    move.percent_margin = 0
Exemple #17
0
class MrpProduction(osv.Model):
    _inherit = 'mrp.production'

    _columns = {
        'bom_qty':
        fields.related('bom_id',
                       'product_qty',
                       type='float',
                       string='Bom Qty',
                       store=True,
                       digits_compute=dp.get_precision('Product UoM'),
                       readonly=True,
                       states={'draft': [('readonly', False)]},
                       help="BoM's Quantity to change from production order"),
        'bom_uom':
        fields.related('bom_id',
                       'product_uom',
                       type='many2one',
                       relation='product.uom',
                       string='Bom UoM',
                       store=True,
                       readonly=True,
                       states={'draft': [('readonly', False)]},
                       help="BoM's UoM to change from production order"),
    }
Exemple #18
0
class AnalyticHistoryBrokerLine(models.Model):
    _name = 'analytic_history.broker.line'
    _description = 'Broker of contract version'

    name = fields.Many2one(comodel_name='res.partner',
                           string='Broker',
                           domain="[('is_broker', '=', True)]",
                           help='List of broker')
    rate = fields.Float(string='Rate',
                        digits_compute=dp.get_precision('Account'),
                        help='Rate for broker')
    amount = fields.Float(string='Amount',
                          digits_compute=dp.get_precision('Account'),
                          help='Fixed amount for broker')
    history_id = fields.Many2one(comodel_name='analytic.history',
                                 string='History')
class sale_commission(osv.Model):
    def _get_commission(self, cr, uid, ids, name, args, context=None):
        res = {}

        for so_brw in self.browse(cr, uid, ids):
            res[so_brw.id] = 0.0
            for sol_brw in so_brw.order_line:
                res[so_brw.id] += sol_brw.commission
        return res

    def _get_order_line(self, cr, uid, ids, context=None):
        res = {}
        for line in self.pool.get('sale.order.line').browse(cr,
                                                            uid,
                                                            ids,
                                                            context=context):
            res[line.order_id.id] = True
        return res.keys()

    _inherit = 'sale.order'
    _columns = {
        'commission':
        fields.function(_get_commission,
                        method=True,
                        type='float',
                        string='Commission',
                        digits_compute=dp.get_precision('Commission'),
                        store={
                            'sale.order':
                            (lambda self, cr, uid, ids, c={}: ids,
                             ['order_line', 'state'], 25),
                            'sale.order.line':
                            (_get_order_line, ['gain', 'commission'], 15),
                        })
    }
class MrpConsumeLine(osv.TransientModel):
    _name = 'mrp.consume.line'
    _rec_name = 'product_id'
    _columns = {
        'product_id':
        fields.many2one('product.product', string="Product", required=True),
        'quantity':
        fields.float("Quantity",
                     digits_compute=dp.get_precision('Product UoM'),
                     required=True),
        'product_uom':
        fields.many2one(
            'product.uom',
            'Unit of Measure',
            required=True,
        ),
        'consume_line_move_ids':
        fields.one2many(
            'mrp.consume.line.move',
            'consume_line_id',
            'Moves',
            required=True,
            help='Moves corresponding to the product in the consume line'),
        'wizard_id':
        fields.many2one('mrp.consume', string="Wizard"),
    }
class MrpProduceLine(osv.TransientModel):

    _name = 'mrp.produce.line'
    _rec_name = 'product_id'
    _columns = {
        'product_id':
        fields.many2one('product.product',
                        'Product',
                        required=True,
                        help='Product to be Produce'),
        'quantity':
        fields.float('Quantity',
                     digits_compute=dp.get_precision('Product UoM'),
                     required=True,
                     help='Quantity that will be produced'),
        'product_uom':
        fields.many2one('product.uom',
                        'Unit of Measure',
                        required=True,
                        help='Units of measure corresponding to the quantity'),
        'move_id':
        fields.many2one('stock.move', "Move"),
        'location_id':
        fields.many2one('stock.location', 'Location', required=True),
        'location_dest_id':
        fields.many2one('stock.location', 'Dest. Location', required=True),
        'produce_id':
        fields.many2one('mrp.produce', 'Produce Wizard'),
    }
class hr_payroll_analysis(osv.Model):
    _name = "hr.payroll.analysis"
    _description = "Análisis Roles"
    _auto = False
    _rec_name = 'orden'
    _order = 'orden'

    _columns = {
        'date_create': fields.datetime('Fecha', readonly=True),
        'salary_rule_id': fields.many2one('hr.salary.rule', 'Descripcion',readonly=True),
        'department_id': fields.many2one('hr.department','Departamento',readonly=True),
        'amount': fields.float('Valor', digits_compute=dp.get_precision('Payroll'),readonly=True),
        'orden': fields.integer('Orden', readonly=True),
    }
    
    def init(self, cr):
        tools.drop_view_if_exists(cr, 'hr_payroll_analysis')
        cr.execute("""
            create or replace view hr_payroll_analysis as (
                select 
                    min(pl.id) as id, 
                    pl.create_date as date_create,
                    pl.department_id as department_id,
                    pl.salary_rule_id,
                    sum(pl.amount) as amount, 
                    sr.sequence as orden
                from hr_payslip_line pl, hr_salary_rule sr
                where pl.salary_rule_id = sr.id
                and sr.code in ('INGHXT','INGHSUP','INGHNOC')
                group by  pl.create_date, pl.department_id, salary_rule_id, orden
                order by orden
            )
        """)
class DevModelType(models.Model):
    _name = "dev.model.type"
    _description = "Development Model Type"

    name = fields.Char(
        string="# Document",
        required=True,
    )
    code = fields.Char(string="Code", )
    partner_id = fields.Many2one(
        string="Partner",
        comodel_name="res.partner",
    )
    value = fields.Float(
        string="Value",
        digits_compute=dp.get_precision("Account"),
    )
    sequence_id = fields.Many2one(
        string="Sequence",
        comodel_name="ir.sequence",
    )
    active = fields.Boolean(
        string="Active",
        default=True,
    )
    notes = fields.Text(string="Notes", )
Exemple #24
0
class StatementGenericAccountLine(orm.Model):
    _name = 'statement.generic.account.line'
    _columns = {
        'account_id':
        fields.many2one('account.account', 'Account', required=True),
        'statement_id':
        fields.many2one('account.vat.period.end.statement', 'VAT statement'),
        'amount':
        fields.float('Amount',
                     digits_compute=dp.get_precision('Account'),
                     required=True),
    }

    def on_change_vat_account_id(self,
                                 cr,
                                 uid,
                                 ids,
                                 vat_account_id=False,
                                 context=None):
        res = {}
        res['value'] = {}
        if not vat_account_id:
            return res
        res['value']['amount'] = self.pool.get('account.account').browse(
            cr, uid, vat_account_id, context).balance
        return res
Exemple #25
0
class CustomsFormLine(osv.osv):

    _name = 'customs.form.line'
    _description = ''
    _rec_name = 'tax_code'

    _columns = {
        'customs_form_id': fields.many2one('customs.form', 'Customs',
                                           required=True, ondelete='cascade'),
        'tax_code': fields.many2one('customs.duty', 'Tax',
                                    ondelete='restrict', required=True,
                                    readonly=False),
        'amount': fields.float('Amount', required=True,
                               digits_compute=dp.get_precision('Account')),
        'imex_tax_line': fields.one2many(
            'account.invoice.tax', 'cfl_id', 'Vat lines',
            attrs="{'readonly':[('vat_detail','=',True)], \
            'required':[('vat_detail','=',True)]}"),
        'vat_detail': fields.related('tax_code', 'vat_detail', type='boolean',
                                     string='Tax detail', store=False,
                                     readonly=True)
    }

    _sql_constraints = [
        ('code_uniq', 'UNIQUE(customs_form_id,tax_code)',
         'The code must be unique! (for this form)'),
    ]
Exemple #26
0
class invoice_commission(osv.Model):
    def _get_commission(self, cr, uid, ids, name, args, context=None):
        res = {}
        for ai_brw in self.browse(cr, uid, ids):
            res[ai_brw.id] = 0.0
            if ai_brw.type in ['out_invoice', 'out_refound']:
                for iol_brw in ai_brw.invoice_line:
                    res[ai_brw.id] += iol_brw.commission
        return res

    def _get_invoice_line(self, cr, uid, ids, context=None):
        res = {}
        for line in self.pool.get('account.invoice.line').browse(
                cr, uid, ids, context=context):
            res[line.invoice_id.id] = True
        return res.keys()

    _inherit = 'account.invoice'
    _columns = {
        'commission':
        fields.function(_get_commission,
                        method=True,
                        type='float',
                        string='Commission',
                        digits_compute=dp.get_precision('Commission'),
                        store={
                            'account.invoice':
                            (lambda self, cr, uid, ids, c={}: ids,
                             ['invoice_line', 'state'], 25),
                            'account.invoice.line':
                            (_get_invoice_line, ['gain', 'commission'], 15),
                        })
    }
class BankingExportSdd(models.Model):
    """SEPA Direct Debit export"""
    _name = 'banking.export.sdd'
    _description = __doc__
    _rec_name = 'filename'

    @api.one
    @api.depends('payment_order_ids', 'payment_order_ids.reference')
    def _generate_filename(self):
        if self.payment_order_ids:
            ref = self.payment_order_ids[0].reference
            label = unidecode(ref.replace('/', '-')) if ref else 'error'
            filename = 'sdd_%s.xml' % label
        else:
            filename = 'sdd.xml'
        self.filename = filename

    payment_order_ids = fields.Many2many(
        comodel_name='payment.order',
        relation='account_payment_order_sdd_rel',
        column1='banking_export_sepa_id',
        column2='account_order_id',
        string='Payment Orders',
        readonly=True)
    nb_transactions = fields.Integer(string='Number of Transactions',
                                     readonly=True)
    total_amount = fields.Float(string='Total Amount',
                                digits_compute=dp.get_precision('Account'),
                                readonly=True)
    batch_booking = fields.Boolean(
        'Batch Booking',
        readonly=True,
        help="If true, the bank statement will display only one credit line "
        "for all the direct debits of the SEPA file ; if false, the bank "
        "statement will display one credit line per direct debit of the "
        "SEPA file.")
    charge_bearer = fields.Selection(
        [('SLEV', 'Following Service Level'), ('SHAR', 'Shared'),
         ('CRED', 'Borne by Creditor'), ('DEBT', 'Borne by Debtor')],
        'Charge Bearer',
        readonly=True,
        help="Following service level : transaction charges are to be applied "
        "following the rules agreed in the service level and/or scheme "
        "(SEPA Core messages must use this). Shared : transaction "
        "charges on the creditor side are to be borne by the creditor, "
        "transaction charges on the debtor side are to be borne by the "
        "debtor. Borne by creditor : all transaction charges are to be "
        "borne by the creditor. Borne by debtor : all transaction "
        "charges are to be borne by the debtor.")
    create_date = fields.Datetime(string='Generation Date', readonly=True)
    file = fields.Binary(string='SEPA File', readonly=True)
    filename = fields.Char(compute=_generate_filename,
                           size=256,
                           string='Filename',
                           readonly=True,
                           store=True)
    state = fields.Selection([('draft', 'Draft'), ('sent', 'Sent')],
                             string='State',
                             readonly=True,
                             default='draft')
Exemple #28
0
class MrpPtPlanified(osv.Model):
    _name = 'mrp.pt.planified'
    _rec_name = 'product_id'

    _columns = {
        'product_id':
        fields.many2one('product.product', 'Product', required=True),
        'quantity':
        fields.float('quantity',
                     digits_compute=dp.get_precision('Product UoM'),
                     required=True),
        'production_id':
        fields.many2one('mrp.production', 'production'),
        'product_uom':
        fields.many2one('product.uom', 'UoM', required=True)
    }

    def on_change_product_uom(self, cr, uid, ids, product_id):
        product_product = self.pool.get('product.product')
        if product_id:
            product = product_product.browse(cr, uid, product_id)
            return {
                'value': {
                    'product_uom': product.uom_id and product.uom_id.id
                }
            }
        return {'value': {'product_uom': False}}
Exemple #29
0
class mrp_production(models.Model):

    _inherit = 'mrp.production'

    @api.one
    def _consume_or_produce_pending(self):
        self.consume_or_produce_pending = not self.test_production_done()

    @api.one
    def _produced_qty(self):
        self.produced_qty = self._get_produced_qty(self)

    consume_or_produce_pending = fields.Boolean(
        'Has pending moves',
        compute=_consume_or_produce_pending,
        help='Technical field that '
        'calculates if production has'
        ' pending moves')
    # consumed and produced fields must not show cancelled moves
    move_lines2 = fields.One2many('stock.move',
                                  'raw_material_production_id',
                                  'Consumed products',
                                  domain=[('state', 'in', ('done', ))])
    move_created_ids2 = fields.One2many('stock.move',
                                        'production_id',
                                        'Produced products',
                                        domain=[('state', 'in', ('done', ))])
    produced_qty = fields.Float(
        'Produced qty.',
        digits=dp.get_precision('Product Unit of Measure'),
        compute=_produced_qty)
    # On v6.1, this field had no readonly restrictions according to state.
    workcenter_lines = fields.One2many(
        comodel_name="mrp.production.workcenter.line",
        inverse_name="production_id",
        string="Operations",
        readonly=True,
        states={
            'draft': [('readonly', False)],
            'confirmed': [('readonly', False)],
            'ready': [('readonly', False)],
            'in_production': [('readonly', False)]
        })

    @api.one
    def action_produce(self,
                       production_qty,
                       production_mode,
                       wiz=False,
                       context=None):
        # Invalidate action_produce method (see module description).
        return True

    @api.multi
    def action_production_end(self):
        for record in self:
            # Cancel pending consumes and productions
            moves = record.move_lines + record.move_created_ids
            moves.action_cancel()
        return super(mrp_production, self).action_production_end()
Exemple #30
0
class product_historic_cost(osv.Model):
    _order = "name desc"
    _name = "product.historic.cost"
    _description = "Historical Price List"

    _columns = {
        'product_id':
        fields.many2one('product.template',
                        string='Product related to this Cost',
                        required=True),
        'name':
        fields.datetime(string='Date', required=True),
        'price':
        fields.float(string='Cost', digits_compute=dp.get_precision('Price2')),
        'product_uom':
        fields.many2one('product.uom',
                        string="Supplier UoM",
                        help="""Choose here the Unit of Measure
                                               in which the prices and
                                               quantities are expressed
                                               below.""")
    }
    _defaults = {
        'name': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
    }
    def _match_payment(self, cr, uid, trans, payment_lines,
                      partner_ids, bank_account_ids, log, linked_payments):
        '''
        Find the payment order belonging to this reference - if there is one
        This is the easiest part: when sending payments, the returned bank info
        should be identical to ours.
        This also means that we do not allow for multiple candidates.
        '''
        # TODO: Not sure what side effects are created when payments are done
        # for credited customer invoices, which will be matched later on too.

        def bank_match(account, partner_bank):
            """
            Returns whether a given account number is equivalent to a
            partner bank in the database. We simply call the search method,
            which checks IBAN, domestic and disregards from spaces in IBANs.

            :param account: string representation of a bank account number
            :param partner_bank: browse record of model res.partner.bank
            """
            return partner_bank.id in self.pool['res.partner.bank'].search(
                cr, uid, [('acc_number', '=', account)])

        digits = dp.get_precision('Account')(cr)[1]
        candidates = [
            line for line in payment_lines
            if (line.communication == trans.reference 
                and round(line.amount, digits) == -round(
                    trans.statement_line_id.amount, digits)
                and bank_match(trans.remote_account, line.bank_id))
            ]
        if len(candidates) == 1:
            candidate = candidates[0]
            # Check cache to prevent multiple matching of a single payment
            if candidate.id not in linked_payments:
                linked_payments[candidate.id] = True
                move_info = self._get_move_info(
                    cr, uid, [candidate.move_line_id.id])
                move_info.update({
                        'match_type': 'payment',
                        'payment_line_id': candidate.id,
                        })
                return move_info

        return False
    def split(self, cr, uid, ids, move_ids, context=None):
        #~ """ To split stock moves into production lot
        #~ @param self: The object pointer.
        #~ @param cr: A database cursor
        #~ @param uid: ID of the user currently logged in
        #~ @param ids: the ID or list of IDs if we want more than one
        #~ @param move_ids: the ID or list of IDs of stock move we want to split
        #~ @param context: A standard dictionary
        #~ @return:
        #~ """
        check_aux = True
        if context is None:
            context = {}
        inventory_id = context.get('inventory_id', False)
        prodlot_obj = self.pool.get('stock.production.lot')
        inventory_obj = self.pool.get('stock.inventory')
        move_obj = self.pool.get('stock.move')
        new_move = []

        for data in self.browse(cr, uid, ids, context=context):

            check = self.check_serial(cr, uid, ids, data, context=context)

            if check:
                raise osv.except_osv(_("User Error"), _(
                    "These serial has already been used \n%s") % check)

            for move in move_obj.browse(cr, uid, move_ids, context=context):
                move_qty = move.product_qty
                quantity_rest = move.product_qty
                uos_qty_rest = move.product_uos_qty
                new_move = []
                total_move_qty = 0.0
                psm = data.psm
                if psm:
                    lines = psm.split('\n')
                    lines = list(set(lines))
                    if '' in lines:
                        lines.remove('')
                else:
                    lines = []

                for line in lines:
                    if move.product_id.track_serial_incoming and move.product_id.track_serial_outgoing and move.picking_id.type == 'out':
                        spl_ids = prodlot_obj.search(cr, uid, [(
                            'product_id', '=', move.product_id.id), ('name', '=', line)])
                        if len(spl_ids) < 1:
                            raise osv.except_osv(_('Error !'), _(
                                'This serial %s is not exist') % line)

                if move.picking_id.type == "in":
                    self.track_serial_incoming(
                        cr, uid, ids, data.product_id.id, lines, context=context)
                    check_aux = False

                for line in lines:
                    quantity = 1
                    total_move_qty += quantity
                    if total_move_qty > move_qty:
                        precision = '%0.' + str(dp.get_precision(
                            'Product UoM')(cr)[1] or 0) + 'f'
                        raise osv.except_osv(_('Processing Error'), _('Processing quantity %s for %s is larger than the available quantity %s!')
                                             % (precision % total_move_qty, move.product_id.name, precision % move_qty))
                    if quantity <= 0 or move_qty == 0:
                        continue
                    quantity_rest -= quantity
                    uos_qty = quantity / move_qty * move.product_uos_qty
                    uos_qty_rest = quantity_rest / \
                        move_qty * move.product_uos_qty
                    if quantity_rest < 0:
                        quantity_rest = quantity
                        break
                    default_val = {
                        'product_qty': quantity,
                        'product_uos_qty': uos_qty,
                        'state': move.state
                    }
                    if quantity_rest > 0:
                        current_move = move_obj.copy(
                            cr, uid, move.id, default_val, context=context)
                        if inventory_id and current_move:
                            inventory_obj.write(cr, uid, inventory_id, {
                                                'move_ids': [(4, current_move)]}, context=context)
                        new_move.append(current_move)

                    if quantity_rest == 0:
                        current_move = move.id

                    picking = self.pool.get('stock.move').browse(cr, uid, context.get(
                        'active_ids'), context=context)[0].picking_id

                    if picking.type == 'out':

                        spl_id = prodlot_obj.search(cr, uid, [(
                            'product_id', '=', move.product_id.id), ('name', '=', line)])
                        if spl_id:
                            prodlot_obj.write(cr, uid, [spl_id], {'check_serial': True, 'ref': self.pool.get(
                                'ir.sequence').get(cr, uid, 'psm.stock.production.lot') + ':' + picking.name})

                            prodlot_brw = prodlot_obj.browse(
                                cr, uid, [spl_id], context=context)[0]

                            if not prodlot_brw.check_serial:

                                prodlot_id = prodlot_brw.id
                            else:
                                raise osv.except_osv(_('Error !'), _(
                                    'These serial already by used in other outgoing picking %s ') % '\n'.join(res))
                        else:
                            prodlot_id = False
                            if not prodlot_id:
                                picking = self.pool.get('stock.move').browse(cr, uid, context.get(
                                    'active_ids'), context=context)[0].picking_id
                                prodlot_id = prodlot_obj.create(cr, uid, {
                                    'name': line,
                                    'product_id': move.product_id.id,
                                    'ref': self.pool.get('ir.sequence').get(cr, uid, 'psm.stock.production.lot') + ':' + picking.name,
                                    'check_serial': check_aux,
                                    'company_id': picking.company_id.id,
                                }, context=context)
                    else:
                        prodlot_id = False
                        if not prodlot_id:
                            picking = self.pool.get('stock.move').browse(cr, uid, context.get(
                                'active_ids'), context=context)[0].picking_id
                            prodlot_id = prodlot_obj.create(cr, uid, {
                                'name': line,
                                'product_id': move.product_id.id,
                                'ref': self.pool.get('ir.sequence').get(cr, uid, 'psm.stock.production.lot') + ':' + picking.name,
                                'check_serial': check_aux,
                                'company_id': picking.company_id.id,
                            }, context=context)

                    move_obj.write(cr, uid, [current_move], {
                                   'prodlot_id': prodlot_id, 'state': move.state})

                    update_val = {}
                    if quantity_rest > 0:
                        update_val['product_qty'] = quantity_rest
                        update_val['product_uos_qty'] = uos_qty_rest
                        update_val['state'] = move.state
                        move_obj.write(cr, uid, [move.id], update_val)

        return new_move