diff --git a/ext/custom-addons/dp_custom/models/account.py b/ext/custom-addons/dp_custom/models/account.py index 281902a9..e07385a7 100644 --- a/ext/custom-addons/dp_custom/models/account.py +++ b/ext/custom-addons/dp_custom/models/account.py @@ -82,6 +82,17 @@ class AccountInvoice(models.Model): layout_category_id = fields.Many2one('sale.layout_category', related='invoice_line_ids.layout_category_id', string='Section') + @api.multi + @api.onchange('partner_shipping_id') + def onchange_partner_shipping_id(self): +# res = super(AccountInvoice, self).onchange_partner_shipping_id() + if not self.env.user.has_group('dp_custom.group_allow_third_country_sale'): + if self.partner_invoice_id.country_id != self.partner_shipping_id.country_id: + message = _('Rechnungs- und Lieferland passen nicht zusammen: %s <-> %s!') % \ + (self.partner_invoice_id.country_id.name, self.partner_shipping_id.country_id.name) + + raise Warning(_(message)) + @api.multi def action_invoice_open(self): to_open_invoices = self.filtered(lambda inv: inv.state != 'open') diff --git a/ext/custom-addons/dp_custom/models/product.py b/ext/custom-addons/dp_custom/models/product.py index 704e4262..d6e77aaa 100644 --- a/ext/custom-addons/dp_custom/models/product.py +++ b/ext/custom-addons/dp_custom/models/product.py @@ -264,8 +264,12 @@ class ProductPricelistItem(models.Model): response = requests.post(portal_url + '/api/v1/update-pricelist/?secret=' + application_id, data=json.dumps(data)) if response.status_code != 200: - data = response.json() - error_string = data.get('errors', []) + try: + data = response.json() + error_string = data.get('errors', []) + except: + error_string = response.reason + raise ValidationError(_('Rabatt konnte nicht gesetzt werden. ' 'Status Code: %s, Reason: %s') % (response.status_code, error_string)) diff --git a/ext/custom-addons/dp_custom/models/res_partner.py b/ext/custom-addons/dp_custom/models/res_partner.py index 78621539..ecea14d2 100644 --- a/ext/custom-addons/dp_custom/models/res_partner.py +++ b/ext/custom-addons/dp_custom/models/res_partner.py @@ -120,6 +120,14 @@ class Partner(models.Model): ('portal_id_uniq', 'unique(portal_id)', 'Die Portal-ID muss eindeutig sein') ] + @api.depends('name', 'email') + def _compute_email_formatted(self): + for partner in self: + try: + partner.email_formatted = formataddr((partner.name or u"False", partner.email or u"False")) + except: + partner.email_formatted = partner.email + @api.multi @api.constrains('property_product_pricelist') def _check_property_product_pricelist(self): @@ -603,8 +611,9 @@ class Partner(models.Model): @api.multi def write(self, vals): - # if not self.company_id and self.user_ids and self.env.uid != 1: - # raise ValidationError(_('Dieser Datensatz gehört zu einem Benutzer und darf nur vom System-Administrator bearbeitet werden!')) + for partner in self: + if not partner.company_id and partner.user_ids.id and self.env.uid != 1: + raise ValidationError(_('Dieser Datensatz gehört zu einem Benutzer und darf nur vom System-Administrator bearbeitet werden!')) fields_to_check = ['ref', 'portal_id'] for field in fields_to_check: diff --git a/ext/custom-addons/dp_custom/models/sale.py b/ext/custom-addons/dp_custom/models/sale.py index 5f34eaff..7bd3bf93 100644 --- a/ext/custom-addons/dp_custom/models/sale.py +++ b/ext/custom-addons/dp_custom/models/sale.py @@ -22,7 +22,7 @@ import re from datetime import datetime from odoo import api, fields, models, _ -from odoo.exceptions import ValidationError, UserError +from odoo.exceptions import ValidationError, UserError, Warning from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT from odoo.tools import float_compare from odoo.tools import float_is_zero @@ -154,13 +154,27 @@ class SaleOrder(models.Model): def _onchange_partner_invoice_id(self): for record in self: # record.partner_flash = record.partner_id.partner_flash + if not self.env.user.has_group('dp_custom.group_allow_third_country_sale'): + if record.partner_invoice_id.country_id != record.partner_shipping_id.country_id: + message = _('Rechnungs- und Lieferland passen nicht zusammen: %s <-> %s!') % \ + (record.partner_invoice_id.country_id, record.partner_shipping_id.country_id) + + raise Warning(_(message)) + if record.partner_invoice_id.is_retailer: - record.payment_term_id = record.partner_invoice_id.property_payment_term_id + record.payment_term_id = record.partner_invoice_id.property_payment_term_id @api.multi @api.onchange('partner_shipping_id') def onchange_partner_shipping_id(self): res = super(SaleOrder, self).onchange_partner_shipping_id() + if not self.env.user.has_group('dp_custom.group_allow_third_country_sale'): + if self.partner_invoice_id.country_id != self.partner_shipping_id.country_id: + message = _('Rechnungs- und Lieferland passen nicht zusammen: %s <-> %s!') % \ + (self.partner_invoice_id.country_id.name, self.partner_shipping_id.country_id.name) + + raise Warning(_(message)) + self.carrier_id = self.partner_shipping_id.property_delivery_carrier_id return {} @@ -505,6 +519,8 @@ class SaleOrder(models.Model): current_sequence += 1 order_line.update({'sequence': current_sequence,}) + # order.partner_id.last_order_changed = datetime.now() + return order @api.multi @@ -520,6 +536,14 @@ class SaleOrder(models.Model): vals['delivery_date'] = self.delivery_date res = super(SaleOrder, self).write(vals) + + # if self.partner_invoice_id.country_id != self.partner_shipping_id.country_id: + # message = _('Rechnungs- und Lieferland passen nicht zusammen: %s <-> %s!') % \ + # (self.partner_invoice_id.country_id, self.partner_shipping_id.country_id) + # + # raise Warning(_(message)) + # + if vals.get('assembly_state', False) == 'done': self.message_post(body='Produktion fertig') @@ -529,6 +553,8 @@ class SaleOrder(models.Model): if vals.get('order_line',False): self._reset_sequence() + self.partner_id.last_order_changed = datetime.now() + return res @api.multi @@ -893,7 +919,7 @@ class SaleOrderLine(models.Model): pricelist_id = self.order_id.partner_invoice_id.property_product_pricelist price, rule_id = pricelist_id.with_context(pricelist_context).get_product_price_rule( self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_invoice_id) - new_list_price, currency_id = self.with_context(context_partner)._get_real_price_currency(self.product_id, + new_list_price, currency_id = self.with_context(context_partner).sudo()._get_real_price_currency(self.product_id, rule_id, self.product_uom_qty, self.product_uom, diff --git a/ext/custom-addons/tz_last_order/models/res_partner.py b/ext/custom-addons/tz_last_order/models/res_partner.py index 23714a37..2871c7f6 100644 --- a/ext/custom-addons/tz_last_order/models/res_partner.py +++ b/ext/custom-addons/tz_last_order/models/res_partner.py @@ -5,10 +5,15 @@ from odoo import fields, models, api class ResPartner(models.Model): _inherit = "res.partner" + # last_order = fields.Char(string="Letzter Auftrag", readonly=True, copy=False) + # last_order_date = fields.Date(string="Letztes Auftragsdatum", store=True, copy=False) + last_order = fields.Char(string="Letzter Auftrag", readonly=True, compute="get_last_order", store=True, copy=False) last_order_date = fields.Date(string="Letztes Auftragsdatum", readonly=True, compute="get_last_order", store=True, copy=False) + last_order_changed = fields.Date(string="Letzte Auftragsänderung", readonly=True, copy=False) @api.multi + @api.depends('last_order_changed') def get_last_order(self): for partner in self: order_ids = self.env['sale.order'].search([('partner_id', '=', partner.id),