Browse Source

duplication operation

master
root 3 years ago
parent
commit
4d08bde23b
12 changed files with 189 additions and 41 deletions
  1. +2
    -1
      __init__.py
  2. +2
    -1
      __manifest__.py
  3. +53
    -2
      models/operation.py
  4. +66
    -29
      models/payment_batch.py
  5. +10
    -0
      models/product.py
  6. +2
    -0
      security/ir.model.access.csv
  7. +2
    -2
      views/operation.xml
  8. +1
    -1
      views/payment_batch.xml
  9. +5
    -5
      views/templates.xml
  10. +1
    -0
      wizard/__init__.py
  11. +17
    -0
      wizard/operation_duplicate_wizard.py
  12. +28
    -0
      wizard/operation_duplicate_wizard.xml

+ 2
- 1
__init__.py View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import controllers from . import controllers
from . import models
from . import models
from . import wizard

+ 2
- 1
__manifest__.py View File

@ -38,7 +38,8 @@
'views/returnmail.xml', 'views/returnmail.xml',
'views/payment_batch.xml', 'views/payment_batch.xml',
'views/website_sale.xml', 'views/website_sale.xml',
'views/templates.xml'
'wizard/operation_duplicate_wizard.xml'
], ],
# only loaded in demonstration mode # only loaded in demonstration mode


+ 53
- 2
models/operation.py View File

@ -1,4 +1,4 @@
from odoo import models, fields, api
from odoo import models, fields, api,_
from odoo.exceptions import UserError, ValidationError,Warning from odoo.exceptions import UserError, ValidationError,Warning
from psycopg2 import sql, DatabaseError from psycopg2 import sql, DatabaseError
@ -30,7 +30,7 @@ class opendons_operation(models.Model):
_inherit = ['mail.thread'] _inherit = ['mail.thread']
#_order = "__last_update desc" #_order = "__last_update desc"
#code=fields.Char(string='Code',required=True, translate=True,track_visibility='always') #code=fields.Char(string='Code',required=True, translate=True,track_visibility='always')
name=fields.Char(string='Name',required=True, translate=True,track_visibility='always')
name=fields.Char(string='Name',required=True, translate=True,copy=False,default='operation',track_visibility='always')
partner_count = fields.Integer(string="count",readonly=True) partner_count = fields.Integer(string="count",readonly=True)
exported_date=fields.Date(string='Exported Date',track_visibility='always') exported_date=fields.Date(string='Exported Date',track_visibility='always')
#end_date=fields.Date(string='Date end',required=True, translate=True,track_visibility='always') #end_date=fields.Date(string='Date end',required=True, translate=True,track_visibility='always')
@ -292,6 +292,57 @@ class opendons_operation(models.Model):
self.document_fname='operation'+seld.id+'.csv' self.document_fname='operation'+seld.id+'.csv'
return return
def copy(self,default_values=None):
vals={}
vals['name']='copy of ' + self.name
vals['chanel']=self.chanel
vals['user_id']=self._uid
vals['state']='draft'
dup_operation=super(opendons_operation, self).create(vals)
#on duplique les segment de l'opération
for segment_id in self.segment_ids:
#raise Warning(segment_id.id)
seg=self.env['opendons.segment'].search([('id','=',int(segment_id.id))])
if seg:
vals2={}
vals2['operation_id']=dup_operation.id
vals2['name']=seg.name
vals2['mailing_domain']=seg.mailing_domain
#dup_segment=super(opendons_segment,self).create(vals2)
dup_segment=self.env['opendons.segment'].create(vals2)
dup_operation.write({'segment_ids':[(4,dup_segment.id)]})
for ensemble_id in seg.ensemble_ids:
ens=self.env['opendons.ensemble'].search([('id','=',int(ensemble_id.id))])
if ens:
vals3={}
vals3['segment_id']=dup_segment.id
vals3['name']=ens.name
vals3['mailing_domain']=ens.mailing_domain
#dup_segment=super(opendons_segment,self).create(vals2)
dup_ensemble=self.env['opendons.ensemble'].create(vals3)
dup_segment.write({'ensemble_ids':[(4,dup_ensemble.id)]})
for request_id in ens.request_ids:
req=self.env['opendons.request'].search([('id','=',int(request_id.id))])
if req:
vals4={}
vals4['ensemble_id']=dup_ensemble.id
vals4['name']=req.name
vals4['mailing_domain']=req.mailing_domain
#dup_segment=super(opendons_segment,self).create(vals2)
dup_request=self.env['opendons.request'].create(vals4)
dup_ensemble.write({'request_ids':[(4,dup_request.id)]})
#rtn=super(opendons_operation,self).copy(default=default_values)
return dup_operation
class opendons_segment(models.Model): class opendons_segment(models.Model):


+ 66
- 29
models/payment_batch.py View File

@ -1,5 +1,5 @@
from odoo import models, fields, api from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError
from odoo.exceptions import UserError, ValidationError,Warning
from psycopg2 import sql, DatabaseError from psycopg2 import sql, DatabaseError
from werkzeug import utils from werkzeug import utils
@ -27,8 +27,8 @@ class opendons_payment_batch(models.Model):
'Product', 'Product',
required=True, required=True,
domain=[('donation', '=', True)], domain=[('donation', '=', True)],
ondelete='restrict',
store=False
ondelete='restrict'
) )
@ -89,7 +89,7 @@ class opendons_payment_batch(models.Model):
donation_amount = fields.Monetary( donation_amount = fields.Monetary(
'Donation amount', 'Donation amount',
currency_field='currency_id', currency_field='currency_id',
store=False,
) )
# payment_lines = fields.One2many( # payment_lines = fields.One2many(
# 'opendons_payment_batch.lines', # 'opendons_payment_batch.lines',
@ -107,37 +107,62 @@ class opendons_payment_batch(models.Model):
def _onchange_payment_input(self): def _onchange_payment_input(self):
if self.payment_input: if self.payment_input:
inpt=self.payment_input.split(';')
if len(inpt)!=4:raise ValidationError('input string not valid')
partner_id=int(inpt[0])
key=inpt[1]
operation_id=int(inpt[2])
segment_id=int(inpt[3])
partner = self.env['res.partner'].sudo().search(['&',('id','=',int(partner_id)),('key','=',key)])
operation = self.env['res.partner'].sudo().search([('id','=',int(operation_id))])
segment = self.env['res.partner'].sudo().search([('id','=',int(segment_id))])
if not partner : ValidationError('partner not found')
if not operation : ValidationError('operation not found')
if not segment : ValidationError('segment not found')
self.partner_id=partner_id
self.operation_id=operation_id
self.segment_id=segment_id
res=self.action_ajouter_payment()
#si le QRCODE a déjà été utilisé, message d'avertissement
qrcode_exist=self.env['opendons.payment_batch_qrcode'].search([('qrcode','=',self.payment_input)])
if qrcode_exist : raise Warning('qrcode already used')
if self.input_mode=='loyalty':
inpt=self.payment_input.split(';')
if len(inpt)!=4:raise ValidationError('input string not valid')
partner_id=int(inpt[0])
key=inpt[1]
operation_id=int(inpt[2])
segment_id=int(inpt[3])
partner = self.env['res.partner'].sudo().search(['&',('id','=',int(partner_id)),('key','=',key)])
operation = self.env['res.partner'].sudo().search([('id','=',int(operation_id))])
segment = self.env['res.partner'].sudo().search([('id','=',int(segment_id))])
if not partner : ValidationError('partner not found')
if not operation : ValidationError('operation not found')
if not segment : ValidationError('segment not found')
self.partner_id=partner_id
self.operation_id=operation_id
self.segment_id=segment_id
res=self.action_ajouter_payment()
if self.input_mode=='prospect':
inpt=self.payment_input.split(';')
if len(inpt)!=4:raise ValidationError('input string not valid')
partner_string=int(inpt[0])
key=inpt[1]
operation_id=int(inpt[2])
segment_id=int(inpt[3])
#partner = self.env['res.partner'].sudo().search(['&',('id','=',int(partner_id)),('key','=',key)])
operation = self.env['res.partner'].sudo().search([('id','=',int(operation_id))])
segment = self.env['res.partner'].sudo().search([('id','=',int(segment_id))])
#if not partner : ValidationError('partner not found')
if not operation : ValidationError('operation not found')
if not segment : ValidationError('segment not found')
#self.partner_id=partner_id
self.operation_id=operation_id
self.segment_id=segment_id
#res=self.action_ajouter_payment()
def action_ajouter_payment(self): def action_ajouter_payment(self):
vals={} vals={}
vals['payment_batch_id']=self.id vals['payment_batch_id']=self.id
vals['payment_mode_id']=int(self.payment_mode_id) vals['payment_mode_id']=int(self.payment_mode_id)
@ -154,14 +179,26 @@ class opendons_payment_batch(models.Model):
vals['donation_id']=donation.id vals['donation_id']=donation.id
vals['currency_id']=self.currency_id vals['currency_id']=self.currency_id
#vals['company_currency_id']=self.company_currency_id #vals['company_currency_id']=self.company_currency_id
vals['product_id']=int(self.product_id)
vals['product_id']=self.product_id.id
vals['quantity']=1 vals['quantity']=1
vals['unit_price']=self.donation_amount vals['unit_price']=self.donation_amount
donation_line=self.env['donation.line'].create(vals) donation_line=self.env['donation.line'].create(vals)
donation.validate() donation.validate()
vals={}
vals['qrcode']=self.payment_input
self.env['opendons.payment_batch_qrcode'].create(vals)
self.payment_input=False
self.partner_id=False
self.operation_id=False
self.segment_id=False
return True return True
class opendons_payment_batch_qrcode(models.Model):
_name = 'opendons.payment_batch_qrcode'
_description = 'store qrcode to avoid duplicate entries'
qrcode=fields.Char('qrcode')

+ 10
- 0
models/product.py View File

@ -0,0 +1,10 @@
from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError
from psycopg2 import sql, DatabaseError
from werkzeug import utils

+ 2
- 0
security/ir.model.access.csv View File

@ -20,4 +20,6 @@ access_opendons_returnmail,opendons_returnmail,model_opendons_returnmail,donatio
access_opendons_returnmailnpai,opendons_returnmailnpai,model_opendons_returnmail_npai,donation.group_donation_manager,1,1,1,1 access_opendons_returnmailnpai,opendons_returnmailnpai,model_opendons_returnmail_npai,donation.group_donation_manager,1,1,1,1
access_opendons_payment_batch,opendons_payment_batch,model_opendons_payment_batch,donation.group_donation_manager,1,1,1,1 access_opendons_payment_batch,opendons_payment_batch,model_opendons_payment_batch,donation.group_donation_manager,1,1,1,1
access_opendons_payment_batch_qr_code,opendons_payment_batch_qrcode,model_opendons_payment_batch_qrcode,donation.group_donation_manager,1,1,1,1
access_opendons_duplicate_operation_wizard,opendons_duplicate_operation_wizard,model_opendons_operation_duplicate,donation.group_donation_manager,1,1,1,1

+ 2
- 2
views/operation.xml View File

@ -27,7 +27,7 @@
<field name="name">opendons_operations list</field> <field name="name">opendons_operations list</field>
<field name="model">opendons.operation</field> <field name="model">opendons.operation</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree>
<tree duplicate="1">
<field name="id"/> <field name="id"/>
<field name="__last_update"/> <field name="__last_update"/>
@ -124,7 +124,7 @@
<field name="name">opendons_operation Form</field> <field name="name">opendons_operation Form</field>
<field name="model">opendons.operation</field> <field name="model">opendons.operation</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="operation_form">
<form string="operation_form" duplicate="1">
<header> <header>
<button type="object" name="validate" string="Validate" <button type="object" name="validate" string="Validate"
class="oe_highlight" states="draft"/> class="oe_highlight" states="draft"/>


+ 1
- 1
views/payment_batch.xml View File

@ -46,7 +46,7 @@
<field name="product_id" attrs="{'invisible':[('assignment','not in','single')]}"/> <field name="product_id" attrs="{'invisible':[('assignment','not in','single')]}"/>
<br></br> <br></br>
<br></br> <br></br>
<field name="payment_input"/>
<field name="payment_input" style="background:#7CC4F4;" attrs="{'invisible':[('input_mode','in','manual')]}"/>
<field name="partner_id"/> <field name="partner_id"/>
<field name="operation_id"/> <field name="operation_id"/>
<field name="segment_id"/> <field name="segment_id"/>


+ 5
- 5
views/templates.xml View File

@ -2,18 +2,18 @@
<odoo> <odoo>
<template id="opendons_products_item" inherit_id="website_sale.products_item"> <template id="opendons_products_item" inherit_id="website_sale.products_item">
<xpath expr="//t[@t-set='combination_info']" position="after">
<!-- <xpath expr="//t[@t-set='combination_info']" position="after">
<t t-set="special_price" t-value="product._get_special_price(only_template=True, add_qty=add_qty or 1, pricelist=pricelist)"/> <t t-set="special_price" t-value="product._get_special_price(only_template=True, add_qty=add_qty or 1, pricelist=pricelist)"/>
</xpath>
</xpath> -->
<xpath expr="//div[@class='product_price']" position="replace"> <xpath expr="//div[@class='product_price']" position="replace">
<div t-if="not product.donation"> <div t-if="not product.donation">
<del t-attf-class="text-danger mr-2 {{'' if combination_info['has_discounted_price'] else 'd-none'}}" style="white-space: nowrap;" t-esc="combination_info['list_price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}" /> <del t-attf-class="text-danger mr-2 {{'' if combination_info['has_discounted_price'] else 'd-none'}}" style="white-space: nowrap;" t-esc="combination_info['list_price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}" />
Non Adhérent: <span t-if="combination_info['price']" t-esc="combination_info['price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
<br></br>
<span t-if="combination_info['price']" t-esc="combination_info['price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
<!-- <br></br>
Adhérent: <span t-if="special_price['price_adherent']" t-esc="special_price['price_adherent']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/> Adhérent: <span t-if="special_price['price_adherent']" t-esc="special_price['price_adherent']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
<br></br> <br></br>
Soutien et Sangha: <span t-if="special_price['price_soutien']" t-esc="special_price['price_soutien']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
Soutien et Sangha: <span t-if="special_price['price_soutien']" t-esc="special_price['price_soutien']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/> -->
<span itemprop="price" style="display:none;" t-esc="combination_info['price']" /> <span itemprop="price" style="display:none;" t-esc="combination_info['price']" />


+ 1
- 0
wizard/__init__.py View File

@ -0,0 +1 @@
from . import operation_duplicate_wizard

+ 17
- 0
wizard/operation_duplicate_wizard.py View File

@ -0,0 +1,17 @@
from odoo import fields, models, _
class DuplicateOperation(models.TransientModel):
_name = 'opendons.operation.duplicate'
_description = 'Duplicate the operation'
def duplicate_operation(self):
active_ids = self._context.get('active_ids', []) or []
for record in self.env['opendons.operation'].browse(active_ids):
#creation de l'opération sans les segments
vals={}
vals['name']='copy of ' + record.name
vals['chanel']=record.chanel
vals['user_id']=self._uid
vals['state']='draft'
dup_operation=super(opendons_operation, self).create(vals)

+ 28
- 0
wizard/operation_duplicate_wizard.xml View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="operation_duplicate_view" model="ir.ui.view">
<field name="name">duplicate.operation.wizard</field>
<field name="model">opendons.operation.duplicate</field>
<field name="arch" type="xml">
<form>
<button name="duplicate_operation" string="Duplicate" type="object"/>
<footer>
<button string="Cancel" class="btn btn-secondary" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_operation_duplicate" model="ir.actions.act_window">
<field name="name">Duplicate operation</field>
<field name="res_model">opendons.operation.duplicate</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="binding_model_id" ref="opendons.model_opendons_operation"/>
</record>
</odoo>

Loading…
Cancel
Save