details:   https://code.tryton.org/tryton/commit/1dab049ec548
branch:    default
user:      Sergi Almacellas Abellana <[email protected]>
date:      Wed Nov 18 18:40:29 2026 +0100
description:
        Explain how to extend a method in module tutorial
diffstat:

 trytond/doc/tutorial/module/extend.rst |  25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diffs (35 lines):

diff -r 397add08553e -r 1dab049ec548 trytond/doc/tutorial/module/extend.rst
--- a/trytond/doc/tutorial/module/extend.rst    Wed Nov 18 12:14:50 2026 +0100
+++ b/trytond/doc/tutorial/module/extend.rst    Wed Nov 18 18:40:29 2026 +0100
@@ -62,6 +62,31 @@
    You must always call the ``super()`` method when extending an existing
    method.
 
+Extend a method of the Party model
+----------------------------------
+
+To do so, define a method with the same name on the class.
+This allows your module to add behavior to the model from another module.
+
+For example, override the :meth:`~trytond.model.ModelStorage.copy` method to
+clear opportunities when duplicating parties.
+The :file:`party.py` file becomes:
+
+.. code-block:: python
+
+    class Party(metaclass=PoolMeta):
+        ...
+
+        @classmethod
+        def copy(cls, records, default=None):
+            default = {} if default is None else default.copy()
+            default.setdefault('opportunities', None)
+            return super().copy(records, default=default)
+
+This method updates the default values by including the opportunities field.
+Then the ``super()`` method is called to copy the records with the updated
+``default``.
+
 Extend the Party view
 ---------------------
 

Reply via email to