Commit 0937e7ac authored by fedexin40's avatar fedexin40 Committed by agb80

Fix problem that prevents refund invoice created from invoice where signed

When it was created an invoice the field datetime_invoice it was always
write with the same time only changed the date, therefore when we created an
invoice refund from an invoice on same day, the date and time for both documents
were the same  and the returned uuid too as PAC were considering both documents
as only one

Right styles

Deleted this field due to this correction doesn't belong this branch

The invoice date field is visible for everyone, instead of only for who belong to the group_l10n_mx_facturae_user group

Changed osv into orm
parent 75455757
......@@ -265,6 +265,21 @@ class account_invoice(osv.Model):
0] or False
return res
def _get_date_invoice_tz(
self, cr, uid, ids, field_names=None, arg=False, context=None
):
if context is None:
context = {}
res = {}
tz = context.get('tz_invoice_mx', 'America/Mexico_City')
for invoice in self.browse(cr, uid, ids, context=context):
res[invoice.id] = (
invoice.invoice_datetime and tools.server_to_local_timestamp(
invoice.invoice_datetime,
tools.DEFAULT_SERVER_DATETIME_FORMAT,
tools.DEFAULT_SERVER_DATETIME_FORMAT, tz) or False)
return res
_columns = {
# Extract date_invoice from original, but add datetime
# TODO: Is this field really needed?
......@@ -327,23 +342,35 @@ class account_invoice(osv.Model):
# TODO: This field and date_canceled used by same pourpose
'cfdi_fecha_cancelacion': fields.datetime(
'CFD-I Cancellation Date',
help='If the invoice is cancel, this field saved the date when is cancel'
help='If the invoice is cancel, this field '
'saved the date when is cancel'
),
'cfdi_folio_fiscal': fields.char(
'CFD-I Folio Fiscal', size=64,
help='Folio used in the electronic invoice'
),
'invoice_datetime': fields.datetime(
'Date Electronic Invoiced ', states={
'open': [('readonly', True)], 'close': [('readonly', True)]},
help="Keep empty to use the current date"),
'date_invoice_tz': fields.function(
_get_date_invoice_tz, method=True,
type='datetime', string='Date Invoiced with TZ', store=True,
help='Date of Invoice with Time Zone'
),
}
def copy(self, cr, uid, id, default={}, context=None):
if context is None:
context = {}
default.update({
'invoice_datetime': False,
'date_invoice': False,
'invoice_sequence_id': False,
'no_certificado': False,
'certificado': False,
'sello': False,
'cadena_original': False,
'cadena_original': False,
'cfdi_cbb': False,
'cfdi_sello': False,
'cfdi_no_certificado': False,
......@@ -1338,3 +1365,40 @@ class account_invoice(osv.Model):
a = timezone_original + ((
timezone_present + timezone_original) * -1)
return a
def write(self, cr, uid, ids, vals, context=None):
if context is None:
context = {}
if vals.get('date_invoice'):
vals.update({'invoice_datetime': False})
self.assigned_datetime(cr, uid, vals, context=context)
if vals.get('invoice_datetime'):
vals.update({'date_invoice': False})
self.assigned_datetime(cr, uid, vals, context=context)
return super(account_invoice, self).write(
cr, uid, ids, vals, context=context)
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
self.assigned_datetime(cr, uid, vals, context=context)
return super(account_invoice, self).create(cr, uid, vals, context)
def assigned_datetime(self, cr, uid, values, context=None):
import pytz
res_users_obj = self.pool.get('res.users')
userstz = res_users_obj.browse(cr, uid, [uid])[0].partner_id.tz
if context is None:
context = {}
if userstz:
if not values.get('date_invoice'):
values['date_invoice'] = str(datetime.now(
pytz.timezone(userstz)).strftime('%Y-%m-%d'))
values['invoice_datetime'] = str(datetime.now(
pytz.timezone(userstz)).strftime('%Y-%m-%d %H:%M:%S'))
else:
if not values.get('date_invoice'):
values['date_invoice'] = str(
datetime.now().strftime('%Y-%m-%d'))
values['invoice_datetime'] = str(
datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
......@@ -41,10 +41,7 @@
],
"demo" : [],
"data" : [
#"security/dateinvoice_security.xml",
"account_invoice_view.xml"
],
"data" : [],
"installable" : True,
"active" : False,
}
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="account_invoice_datetime">
<field name="name">account.invoice.datetime</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='date_invoice']" position="after">
<field name="invoice_datetime" groups="l10n_mx_facturae_groups.group_l10n_mx_facturae_manager"/>
</xpath>
<xpath expr="//field[@name='date_invoice']" position="replace">
<field name="date_invoice" groups="l10n_mx_facturae_groups.group_l10n_mx_facturae_user"/>
</xpath>
</field>
</record>
</data>
</openerp>
......@@ -25,19 +25,14 @@
#
##############################################################################
from openerp.osv import fields, osv
from openerp import tools
from openerp import release
from openerp.tools.translate import _
import datetime
from openerp.osv import orm
import time
class account_payment_term(osv.Model):
class account_payment_term(orm.Model):
_inherit = "account.payment.term"
def compute(self, cr, uid, id, value, date_ref=False, context=None):
def compute(self, cr, uid, ids, value, date_ref=False, context=None):
if context is None:
context = {}
if date_ref:
......@@ -46,122 +41,5 @@ class account_payment_term(osv.Model):
date_ref, '%Y-%m-%d %H:%M:%S'))
except:
pass
return super(account_payment_term, self).compute(cr, uid, id, value,
date_ref, context=context)
class account_invoice(osv.Model):
_inherit = 'account.invoice'
# _order = 'invoice_datetime asc'
def _get_date_invoice_tz(self, cr, uid, ids, field_names=None, arg=False, context=None):
if context is None:
context = {}
res = {}
if release.version >= '6':
dt_format = tools.DEFAULT_SERVER_DATETIME_FORMAT
tz = context.get('tz_invoice_mx', 'America/Mexico_City')
for invoice in self.browse(cr, uid, ids, context=context):
res[invoice.id] = invoice.invoice_datetime and tools.\
server_to_local_timestamp(invoice.invoice_datetime,
tools.DEFAULT_SERVER_DATETIME_FORMAT,
tools.DEFAULT_SERVER_DATETIME_FORMAT, context.get(
'tz_invoice_mx', 'America/Mexico_City')) or False
elif release.version < '6':
# TODO: tz change for openerp5
for invoice in self.browse(cr, uid, ids, context=context):
res[invoice.id] = invoice.date_invoice
return res
_columns = {
# Extract date_invoice from original, but add datetime
# 'date_invoice': fields.datetime('Date Invoiced', states={'open':[
# ('readonly',True)],'close':[('readonly',True)]},
# help="Keep empty to use the current date"),
'invoice_datetime': fields.datetime('Date Electronic Invoiced ',
states={'open': [('readonly', True)], 'close': [('readonly', True)]},
help="Keep empty to use the current date"),
'date_invoice_tz': fields.function(_get_date_invoice_tz, method=True,
type='datetime', string='Date Invoiced with TZ', store=True,
help='Date of Invoice with Time Zone'),
}
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
res = self.assigned_datetime(cr, uid, vals, context=context)
if res:
vals.update(res)
return super(account_invoice, self).create(cr, uid, vals, context)
def write(self, cr, uid, ids, vals, context=None):
if context is None:
context = {}
res = {}
if vals.get('date_invoice', False):
vals.update({'invoice_datetime': False})
res = self.assigned_datetime(cr, uid, vals, context=context)
if vals.get('invoice_datetime', False):
vals.update({'date_invoice' : False})
res = self.assigned_datetime(cr, uid, vals, context=context)
if res:
vals.update(res)
return super(account_invoice, self).write(cr, uid, ids, vals,
context=context)
def copy(self, cr, uid, id, default=None, context=None):
if context is None:
context = {}
if default is None:
default = {}
default.update({'invoice_datetime': False, 'date_invoice': False})
return super(account_invoice, self).copy(cr, uid, id, default, context)
def assigned_datetime(self, cr, uid, values, context=None):
if context is None:
context = {}
res = {}
if values.get('date_invoice', False) and\
not values.get('invoice_datetime', False):
user_hour = self._get_time_zone(cr, uid, [], context=context)
time_invoice = datetime.time(abs(user_hour), 0, 0)
date_invoice = datetime.datetime.strptime(
values['date_invoice'], '%Y-%m-%d').date()
dt_invoice = datetime.datetime.combine(
date_invoice, time_invoice).strftime('%Y-%m-%d %H:%M:%S')
res['invoice_datetime'] = dt_invoice
res['date_invoice'] = values['date_invoice']
return res
if values.get('invoice_datetime', False) and not\
values.get('date_invoice', False):
date_invoice = fields.datetime.context_timestamp(cr, uid,
datetime.datetime.strptime(values['invoice_datetime'],
tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context)
res['date_invoice'] = date_invoice
res['invoice_datetime'] = values['invoice_datetime']
return res
if 'invoice_datetime' in values and 'date_invoice' in values:
if values['invoice_datetime'] and values['date_invoice']:
date_invoice = datetime.datetime.strptime(
values['invoice_datetime'],
'%Y-%m-%d %H:%M:%S').date().strftime('%Y-%m-%d')
if date_invoice != values['date_invoice']:
raise osv.except_osv(_('Warning!'),
_('Invoice dates should be equal'))
if not values.get('invoice_datetime', False) and\
not values.get('date_invoice', False):
date_ts = fields.datetime.context_timestamp(cr, uid,
datetime.datetime.strptime(fields.datetime.now(),
tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context)
res['date_invoice'] = date_ts
res['invoice_datetime'] = fields.datetime.now()
return res
return res
return super(account_payment_term, self).compute(
cr, uid, ids, value, date_ref, context=context)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment