123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- # -*- encoding: utf-8 -*-
- from openerp import models, api, fields
- from pytz import timezone
- from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT
- from datetime import datetime,timedelta
- DATE_FORMAT = '%Y-%m-%d'
- class SaleOrder(models.Model):
- _inherit = 'sale.order'
- _name = 'sale.order'
- invoice_number = fields.Char('Numero de Factura')
- contado = fields.Boolean('Contado')
- credito = fields.Boolean('Crédito')
- _defaults = {
- 'contado': True
- }
- @api.one
- @api.onchange('credito')
- def cambiar_estado_credito(self):
- self.contado = not self.credito
- @api.one
- @api.onchange('contado')
- def cambiar_estado_contado(self):
- self.credito = not self.contado
- ''' Timezone '''
- def get_timezone(self):
- return timezone(self._context.get('tz') or self.env.user.tz)
- def _convert_str_to_datetime(self, date):
- return datetime.strptime(date,DEFAULT_SERVER_DATETIME_FORMAT)
- @api.multi
- def order_process_now(self):
- """
- Confirms order and creates and validates invoice, confirms pickings.
- """
- for sale in self:
- sale.action_button_confirm()
- inv_id = sale.action_invoice_create()
- if inv_id:
- inv = self.env['account.invoice'].browse(inv_id)
- date = self._convert_str_to_datetime(sale.date_order)
- date = date.strftime(DATE_FORMAT)
- inv.write({
- 'date_invoice':date,
- 'supplier_invoice_number':self.invoice_number,
- 'contado':self.contado,
- 'credito':self.credito
- })
- self.update_state()
- inv.signal_workflow('invoice_open')
- for picking in sale.picking_ids:
- picking.force_assign()
- picking.action_done()
- @api.multi
- def update_state(self):
- for order in self:
- order.write({'state': 'done'})
- return True
- class account_invoice(models.Model):
- _inherit = 'account.invoice'
- _name = 'account.invoice'
- contado = fields.Boolean('Contado')
- credito = fields.Boolean('Crédito')
- _defaults = {
- 'contado': True
- }
- @api.one
- @api.onchange('credito')
- def cambiar_estado_credito(self):
- self.contado = not self.credito
- @api.one
- @api.onchange('contado')
- def cambiar_estado_contado(self):
- self.credito = not self.contado
- class SaleOrderLine(models.Model):
- _inherit = 'sale.order.line'
- _name = 'sale.order.line'
- amount_total = fields.Float(compute='_calculate_total_sale_line',string='Total',default=0.0)
- standard_price = fields.Float(compute='_standard_price',string='Precio de costo',default=0.0)
- discount_id = fields.Many2one(
- 'sale.purchase.discount',
- string='Desc. Costo',
- ondelete='restrict'
- )
- sale_percentage_id = fields.Many2one(
- 'sale.purchase.discount',
- string='% Venta',
- ondelete='restrict'
- )
- @api.depends('price_unit','product_uom_qty')
- def _calculate_total_sale_line(self):
- for line in self:
- line.amount_total = line.product_uom_qty * line.price_unit
- @api.depends('product_id')
- def _standard_price(self):
- for line in self:
- line.standard_price = line.product_id.standard_price
- @api.onchange('discount_id','sale_percentage_id')
- def _calculate_price_unit(self):
- for line in self:
- if line.discount_id and not line.sale_percentage_id:
- price_unit = line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)
- line.price_unit = price_unit + ((price_unit * (line.interest_amount or 0.0))/100)
- if line.sale_percentage_id and not line.discount_id:
- price_unit = line.standard_price + ((line.standard_price * (line.sale_percentage_id.value or 0.0))/100)
- line.price_unit = price_unit + ((price_unit * (line.interest_amount or 0.0))/100)
- if line.discount_id and line.sale_percentage_id:
- price_unit = (line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)) + (((line.standard_price - ((line.standard_price * (line.discount_id.value or 0.0))/100)) * (line.sale_percentage_id.value or 0.0))/100)
- line.price_unit = price_unit + ((price_unit * (line.interest_amount or 0.0))/100)
|